DEPRECATION WARNING
This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.
Hooks¶
Hooks offer an opportunity to step into the process at various points.
They offer the possibility to manipulate data and influence the final
output. Hooks can be used to replace personalized markers, introduced
previously in the HTML template. There is a convention in
templatedisplay to name Hook like ###HOOK.myHook###
.
In templatedisplay, there are 2 available hooks:
- preProcessResult (for pre-processing the HTML template)
- postProcessResult (for post-processing the HTML content)
To facilitate the implementation of a hook, a skeleton file can be
found in
templatedisplay/Documentation/Developers/Hooks/Index.rst
.
Step 1¶
In the ext_localconf.php
of your extension, register the hook:
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['templatedisplay']['postProcessResult']['myHook'][] = 'Tesseract\\Templatedisplay\\Sample\\SampleHook';
Remarks:
- "postProcessResult" can be replaced by "preProcessResult".
- "myHook" can be something else but must correspond to the marker
###HOOK.myHook###
. - Make sure the path of the file is correct and suits your environment.
- Don't forget to clear the configuration cache!
Step 2¶
Write the PHP method that will transform the content.
class SampleHook {
public function postProcessResult($content, $marker, $parentObject) {
$controller = $parentObject->getController();
$data = $controller->cObj->data;
if ($data['uid'] == 11399) {
$_content = '';
$content = str_replace('###HOOK.myHook###', $_content, $content);
}
return $content;
}
}