Getting the page title from the new PageTitle

1k views Asked by At

I'm looking for a way to get the page title set via the new PageTitleProvider API to display it inside a FluidTemplate.

In one of our TYPO3 installations, the page title is used as title, displayed on the page itself. The main PAGE object is set up to render a FLUIDTEMPLATE object. I've implemented the examples on the new PageTitleAPI in the documentation, https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/PageTitleApi/Index.html into my extensions and that works just fine for the tag.

However, within the page itself, the title set in the page is still displayed, not the title I've set in my extension.

I've figured out, that I can instantiate the PageTitleProviderManager, but getTitle still resolves to the page name, not the title I've set, most likely because this object is resolved before the PageTitleProviders are set up by the extensions.

$pageTitleProviderManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\PageTitle\PageTitleProviderManager::class);
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump( $pageTitleProviderManager->getTitle() );
// -> outputs the page name, not the title custom page title

Is there a way to resolve the page title after all Providers are processed and display it in a fluid template?

1

There are 1 answers

0
Bernd Wilke πφ On

I also assume it depends on order of execution. so you need to build an order where your plugin is executed before the page title is rendered in the page template.

nowadays most integrators use the f:cObject viewhelper to render the content with lib.content. that means the content (and your plugin is rendered very late), as the page title is probably rendered before any content in the page template (independend whether you use template variables from the page template or a viewhelper which executes PHP or typoscript in the moment of the rendering.

Here you get a hint how to change the order:

try to render the content (including plugins) into a fluid-variable with the page templating ( e.g.:

page.10 = FLUIDTEMPLATE
page.10.variables.content < styles.content.get

) and try to get the page title when the page fluid is rendered: use a viewhelper to get the page title when the initial FLUID variables are already computed.


of course you also can define a FLUID-variable for the content in the page FLUID template before accessing the page title by viewhelper:
<f:variable name="content"><f:cObject typoscriptObejctPath="lib.content" /></f:variable>