typo3 - How to generate a rating meta tag in TYPO3 with caching?
问题描述
I would like to generate a rich snippet for ratings in my TYPO3 pages. The rating information are fetched via an API, so I need some kind of caching mechanism.
I have some basic knowledge and experience with TYPO3 extensions, but I am not sure about the cleanest solution. I could render the meta tags with the TYPO3 Meta Tag API and cache the fetched information using the TYPO3 Caching Framework.
But I am not sure where to store the logic so that it gets executed at every page visit. I do not want to use a content plugin for obvious reasons. Should I set up a Controller and call the Contoller's function with e.g. some hook?
Thanks for any help!
解决方案
You may have a look at the tslib/class.tslib_fe.php
hooks in TypoScriptFrontendController
class.
Choose the correct one (maybe tslib_fe-PostProc
) and do something like this :
1) Register hook in ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'][] = \Vendor\Name\Hook\AdditionalMetaData::class . '->addRating';
2) Create your class with the following method
<?php
namespace Vendor\Name\Hook;
class AdditionalMetaData
{
/**
* @param array $parameters
* @return void
*/
public function addRating(&$parameters)
{
/** @var TypoScriptFrontendController $tsfe */
$tsfe = &$parameters['pObj'];
// Do your logic here...
}
}
推荐阅读
- gradle - 如何构建和运行协程基础示例?
- mysql - 如何在带有 mysql 包的 Node.js 中使用 SELECT 语句插入具有 FOREIGN KEY 的列
- report - Power BI 中的前 N 个排序
- gpflow - 优化期间的中间梯度
- raku - 绑定到例程参数的严格类型检查
- mysql - 数据库场景优化设计
- nginx - Nginx 入口 pod 在传入的 websocket 连接请求上返回 404
- ansible - 如何在 shell 命令中使用本地注册变量
- laravel - 从 Laravel 4 升级时替换 Str::parseCallback()
- python - 使用 Pandas 将 dat 文件转换为 excel——数字格式为字符串