我想在扩展程序中设置页面标题,因此流体模板中的当前{page}对象也将显示设置的标题。
$GLOBALS['TSFE']->altPageTitle = $pageTitle;
仅设置<title>
标签,对{page.title}无效
我的主要目标:在面包屑中显示详细信息页面的“正确”标题。
有什么方法可以操纵它吗?
答案 0 :(得分:0)
对于缓存的页面和插件,这应该可以工作:
$GLOBALS['TSFE']->page['title'] = $pageTitle;
答案 1 :(得分:0)
我对流体中的{page}对象一无所知,所以我使用了一个与here中的对象相似的ViewHelper来实现它。
/**
* A view helper for setting the document title in the <title> tag.
*
* = Examples =
*
* <page.title mode="prepend" glue=" - ">{blog.name}</page.title>
*
* <page.title mode="replace">Something here</page.title>
*
* <h1><page.title mode="append" glue=" | " display="render">Title</page.title></h1>
*
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
*/
class PageTitleViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* @var bool
*/
protected $escapeOutput = false;
/**
* @param string $mode Method for adding the new title to the existing one.
* @param string $glue Glue the new title to the old title with this string.
* @param string $display If render, this tag displays it's children. By default it doesn't display anything.
* @return string Rendered content or blank depending on display mode.
* @author Nathan Lenz <nathan.lenz@organicvalley.coop>
*/
public function render($mode = 'replace', $glue = ' - ', $display = 'none') {
$renderedContent = $this->renderChildren();
$existingTitle = $GLOBALS['TSFE']->page['title'];
if ($mode === 'prepend' && !empty($existingTitle)) {
$newTitle = $renderedContent.$glue.$existingTitle;
} else if ($mode === 'append' && !empty($existingTitle)) {
$newTitle = $existingTitle.$glue.$renderedContent;
} else {
$newTitle = $renderedContent;
}
$GLOBALS['TSFE']->page['title'] = $newTitle;
$GLOBALS['TSFE']->indexedDocTitle = $newTitle;
if ($display === 'render') {
return $renderedContent;
} else {
return '';
}
}
}