The modifyFrontendPage
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 after insert tags have been
replaced. If you want to apply your logic before the replacement of
insert tags, use the outputFrontendTemplate
hook instead.
string $buffer
Content of the rendered front end template.
string $templateName
The template name (e.g. fe_page
) without file extension.
Return the original $buffer
or override with your custom modification.
// src/EventListener/ModifyFrontendPageListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('modifyFrontendPage')]
class ModifyFrontendPageListener
{
public function __invoke(string $buffer, string $templateName): string
{
if ('fe_page' === $templateName) {
// Modify $buffer
}
return $buffer;
}
}