2
votes

I am using TYPO3 9 and I want to implement a sharing functionality based on Fluid. Therefore I want to use the already provided metatags.

I wrote a ViewHelper class to make the metatags available to my Fluid template. Researching for possible solutions I found two things:

  1. Setting meta data via TSFE with $GLOBALS['TSFE']->page['description'] = $newDescription;. But I can't get the data with $GLOBALS['TSFE']->page['description']

  2. Using TYPO3's new MetaTagManager. But it seems that the Manager does not include the metatags set via TypoScript.

Is there another way to read all set metatags in PHP classes?

1

1 Answers

0
votes

Accessing the Meta-Tags added via page.meta TypoScript is not possible during content rendering.

The reason is simple: the content is rendered before the meta tags are processed (see method generatePageContentWithHeader in TYPO3\CMS\Frontend\Http\RequestHandler

A simple workaround would be to process all related meta tags with your Extension / View Helper only.

A more sophisticated approach is a registry of some kind (e.g. a static property) that collects all changes you want to make to existing meta tags. The registry gets filled by your view helper.

Then you can call a userFunc that is executed after the TypoScript meta tags are collected:

page.jsFooterInline.323 = USER
page.jsFooterInline.323.userFunc = My\Extension\Hooks\MetaHook->processMeta

Within the processMeta you can now access the page meta data (e.g. page.meta.description like this:

$registry = GeneralUtility::makeInstance(MetaTagManagerRegistry::class);
$metaDataArray = $registry->getManagerForProperty('description')->getProperty('description');