我正在使用内部链接新闻,这意味着我正在将标准页面用作新闻页面。在这些页面上,我有一个新闻滑块可显示其他新闻。在这里,我需要一个选项:excludeAlreadyDisplayedNews从新闻中删除当前页面。
但是如何在标准页面上添加<n:excludeDisplayedNews newsItem="{newsItem}"/>
?
是否有用于输入此页面相关newsItem的文字记录?也许数据处理程序可以解决问题,但我不知道怎么办?
另一个想法是在页面上添加一个附加字段,因此用户将新闻记录添加到页面上。这是一键单击,确定,但是将新闻UID传递到viewhelper时,出现以下错误消息:
The argument "newsItem" was registered with type "GeorgRinger\News\Domain\Model\News", but is of type "integer" in view helper "GeorgRinger\News\ViewHelpers\ExcludeDisplayedNewsViewHelper".
任何帮助表示赞赏:)
答案 0 :(得分:1)
我认为没有简单,干净的方法可以做到这一点。该页面不是实际的新闻记录,因此从技术上讲不会显示。我可以想到3种可能的解决方案:
实际上,从技术上讲,该新闻记录在页面上显示为带有空模板(n:excludeDisplayedNews
ViewHelper除外),因此它不会显示任何内容。我不确定这是否适用于“内部链接”新闻项,但是如果这样做,这是最简单的方法。
您可以使用以下TypoScript执行此操作:
lib.displayedNews = USER
lib.displayedNews {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
extensionName = News
pluginName = Pi1
vendorName = GeorgRinger
switchableControllerActions {
News {
1 = detail
}
}
views =< plugin.tx_news.view
view {
templateRootPaths.200 = path/to/template/with/only/excludeDisplayedNews/
}
settings =< plugin.tx_news.settings
settings {
singleNews.current = 1
useStdWrap = singleNews
insertRecord = 1
}
}
在页面模板中,您可以使用:
<f:for each="{displayedNews}" as="newsItem">
<f:cObject typoscriptObjectPath="lib.displayedNews" data="{newsItem.data.uid}" />
</f:for>
您的News/Detail.html
模板就是:
<n:excludeDisplayedNews newsItem="{newsItem.uid}" />
使用自定义的ViewHelper或DataProcessor获取新闻记录对象,以便将其填充到n:excludeDisplayedNews
ViewHelper中。我认为这是最干净的解决方案,但也需要最多的工作。
使用户功能填充新闻扩展用来跟踪显示的新闻记录的全局数组,例如:$GLOBALS['EXT']['news']['alreadyDisplayed'][$newsUid] = $newsUid;
答案 1 :(得分:1)
这是完整的解决方案:
第1步:在您的Page Typoscript中,添加一个DataProcessor以获得相关的新闻记录。将此添加到页面FLUIDTEMPLATE Typoscript的dataProcession块中:
10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
10 {
table = tx_news_domain_model_news
#pid for news folder
pidInList = 123
where.data = page : uid
where.wrap = internalurl=|
as = displayedNews
dataProcessing {
10 = MyCompany\MyExtension\DataProcessor\NewsDataProcessor
10 {
field = uid
}
}
}
注意:internalUrl是一个字符串。对我来说,它的工作方式是这样的,但是可能需要输入typolink语法。欢迎任何查询改进!
第2步:在MyExtension / Classes / DataProcessor / NewsDataProcessor.php中添加NewsDataProcessor
<?php
namespace MyCompany\MyExtension\DataProcessor;
use GeorgRinger\News\Domain\Repository\NewsRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
class NewsDataProcessor implements DataProcessorInterface
{
/**
* @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj
* @param array $contentObjectConfiguration
* @param array $processorConfiguration
* @param array $processedData
* @return array
*/
public function process(
ContentObjectRenderer $cObj,
array $contentObjectConfiguration,
array $processorConfiguration,
array $processedData
) {
/** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var \GeorgRinger\News\Domain\Repository\NewsRepository $newsRepository */
$newsRepository = $objectManager->get(NewsRepository::class);
$field = 'uid';
if (array_key_exists('field',$processorConfiguration)) {
$field = $processorConfiguration['field'];
}
$newsArray = $processedData['data'];
$news = $newsRepository->findByUid((int)$newsArray[$field], false);
$processedData['news'] = $news;
return $processedData;
}
}
在更高的EXT:news版本(当前为7.0.7)中,可能有一个DataProcessor可用,那么您可以跳过此步骤并使用现有的
第3步:将n:excludeDisplayedNews Viewhelper添加到页面的Fluid模板中。不要忘记将Viewhelper名称空间添加到模板。
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:n="http://typo3.org/ns/GeorgRinger/News/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:layout name="MyLayout"/>
<f:section name="main">
<f:for each="{displayedNews}" as="newsItem">
<n:excludeDisplayedNews newsItem="{newsItem.news}" />
</f:for>
<div class="main-content">
...
</div>
</f:section>
</html>