TYPO3 - hook / signal after page rendered

Viewed 431

Is there any hook/signal or anything else so that I can modify final HTML code of frontend page rendered by TYPO3?

My use case is: I want to apply some regex and logging for links that are displayed across whole website - no matter if the link is rendered via tt_content bodytext (typolink or hardcoded) or by frontend plugin or comes via typoscript or possibly any other way.

2 Answers

The PAGE object in TypoScript has stdWrap, so you can use userFunc there.

page = PAGE
page {
  ...
  stdWrap.userFunc = Your\NameSpace\YourClass->doStuff
}

If you prefer to use real hooks instead of stdWrap you can look at the function generatePage_postProcessing which has three hooks. In the CoreApi Documentation you can find the way how to use hooks.

In your ext_localconf.php you can define your hook usage. As example:

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-all'][] = My\NameSpace\Hooks\PageGenerateHooks::class . '->contentPostProcAll'

Now in your hook class you can modify the content:

<?php
namespace My\Namespace\Hooks;

use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

class PageGenerateHooks
{

  /*
   * \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $pObj
   */
  public function contentPostProcAll(TypoScriptFrontendController $pObj)
  {
     $pObj->content = preg_replace('#mySearch#i','myTerm', $pObj->content;
  }

}
Related