如何显示一个tx_news标签标题的id?



如果只给出标签的id和pid,我如何在任何流体模板中显示tx_news标签的标题?

最好的选择是使用ViewHelper

<?php
declare(strict_types=1);
namespace VendorPackageViewHelpers;
use TYPO3CMSBackendUtilityBackendUtility;
use TYPO3FluidFluidCoreRenderingRenderingContextInterface;
use TYPO3FluidFluidCoreViewHelperAbstractViewHelper;
use TYPO3FluidFluidCoreViewHelperTraitsCompileWithRenderStatic;
class DbViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* @var bool
*/
protected $escapeOutput = false;
/**
* Initialize arguments
*/
public function initializeArguments(): void
{
$this->registerArgument(
'table',
'string',
'Table (Foreign table)',
true
);
$this->registerArgument(
'id',
'int',
'ID ',
true
);
$this->registerArgument(
'as',
'string',
'This parameter specifies the name of the variable that will be used for the returned ' .
'ViewHelper result.',
true
);
}
/**
* @param array $arguments
* @param Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return mixed
*/
public static function renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$templateVariableContainer = $renderingContext->getVariableProvider();
$row = BackendUtility::getRecord($arguments['table'], $arguments['id']);
$templateVariableContainer->add($arguments['as'], $row);
$content = $renderChildrenClosure();
$templateVariableContainer->remove($arguments['as']);
return $content;
}
}

然后你可以使用

<vendor:db table="tx_news_domain_model_tag" id="123" as="tag">
<strong>{tag.title}</strong>
</vendor:db>

不要忘记在模板中注册命名空间

你可以这样做,

# Add news title if on single view
lib.articleTitle = RECORDS
lib.articleTitle {
if.isTrue.data = 251 # News PID. You can use GP:tx_news_pi1|news if you want
dontCheckPid = 1
tables = tx_news_domain_model_news
source.data = 251 # News PID. You can use GP:tx_news_pi1|news if you want
source.intval = 1
conf.tx_news_domain_model_news = TEXT
conf.tx_news_domain_model_news {
field = title
htmlSpecialChars = 1
}
wrap = |
}

并从流体调用lib对象,

<f:cObject typoscriptObjectPath="lib.articleTitle" />

就是这样!

相关内容

  • 没有找到相关文章

最新更新