outputFrontendTemplate
The outputFrontendTemplate hook is triggered when a front end template is
printed to the screen. It passes the template content and the template name as
arguments and expects the template content as return value.
Info
This hook is applied before the replacement of insert tags
whereas the corresponding modifyFrontendPage is applied after
insert tags have been replaced.
Parameters
string
$bufferContent of the rendered front end template.
string
$templateThe template name (e.g.
fe_page) without file extension.
Return Values
Return the original $buffer or override with your custom modification.
Example
// src/EventListener/OutputFrontendTemplateListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('outputFrontendTemplate')]
class OutputFrontendTemplateListener
{
public function __invoke(string $buffer, string $template): string
{
if ($template === 'fe_page') {
// Modify $buffer
}
return $buffer;
}
}