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.
This hook is applied before the replacement of insert tags
whereas the corresponding modifyFrontendPage
is applied after
insert tags have been replaced.
string $buffer
Content of the rendered front end template.
string $template
The template name (e.g. fe_page
) without file extension.
Return the original $buffer
or override with your custom modification.
// 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;
}
}