Open thomaszbz opened 7 years ago
How to user metaseo connector class to override page title and meta tags: Use connector class in a cacheable action: I would advice to create an extra action, so the plugin can be used in different cases. (e.g. form with extension data over get request).
ext_localconf.php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'VENDOR.' . $_EXTKEY,
'PLUGIN',
array(
'MyController' => 'list, show, meta',
),
// non-cacheable actions
array(
'MyController' => 'show',
)
);
Classes/Controller/MyController.php
/**
* meta action
*
* @param \VENDOR\MyExt\Domain\Model\MyObj $myObj
* @ignorevalidation $myObj
* @return void
*/
public function metaAction(\VENDOR\MyExt\Domain\Model\MyObj $myObj = null) {
if($myObj) {
if(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('metaseo')) {
$title = trim($this->settings['title']['prefix']." ".$myObj->getTitle()." ".$this->settings['title']['suffix']);
$connector = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Metaseo\\Metaseo\\Connector');
$connector->setPageTitle($title);
$connector->setMetaTag('title', $title);
$connector->setOpenGraphTag('title',$title);
if(trim($myObj->getMetakeywords()) != '') {
$connector->setMetaTag('keywords', $myObj->getMetakeywords());
}
if(trim($myObj->getMetadescription()) != '') {
$connector->setMetaTag('description', $myObj->getMetadescription());
}
}
}
}
The prefix and suffix settings could be set via flexform or typoscript constants if needed.
@thomaszbz please check and correct my spelling and grammar before you add this to the documentation :)
@topfender The description should state that it has to be a cacheable action. It won't work with a non cacheable action.
@dsteinborn indeed, thanks.
MetaSEO version: 2.1.0/3.0.0
Add documentation: How to use the connector
Use one of the code examples from #477