Feature: #81464 - Add API for meta tag management¶
See forge#81464
Description¶
The page rendering class Page
now offers a concise, yet simple API to manage meta tags.
It consists of the three methods:
Setting meta tags¶
Page
Used to add or overwrite a given meta tag.
The parameter $type
accepts the values name
, property
or http-
.
All other values result in an exception because those are not within the HTML specs.
The parameter $name
is the value of the attribute given by $type
.
For example:
will result in
Getting meta tags¶
Page
Used to get a given meta tag. This is useful if your extension isn't the only player that handles meta tags. So instead of blindly overwriting other peoples meta tags it is a good idea to check for their existence and provide a feature switch to decide which meta tag should get rendered.
Removing meta tags¶
Page
Used to remove a meta tag from the stack.
Example¶
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
// has meta tag been set already?
$previouslySetMetaTag = $pageRenderer->getMetaTag('property', 'og:title');
// take some decision here
if (!is_array($previouslySetMetaTag) || $yourConfigSwitchToOverwriteMetaTags) {
$pageRenderer->setMetaTag('property', 'og:title', 'My amazing title');
}
Impact¶
Be happy with the new API.