parseFrontendTemplate
The parseFrontendTemplate hook is triggered when a front end template is
parsed. It passes the template content and the template name as arguments
and expects the template content as return value.
Parameters
string
$bufferContent of the parsed front end template.
string
$templateThe template name (e.g.
nav_default) without file extension.\Contao\FrontendTemplate
$templateThe front end template instance.
Return Values
Return the original $buffer or override the template with your custom
modification.
Example
// src/EventListener/ParseFrontendTemplateListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\FrontendTemplate;
#[AsHook('parseFrontendTemplate')]
class ParseFrontendTemplateListener
{
public function __invoke(string $buffer, string $templateName, FrontendTemplate $template): string
{
if ('ce_text' === $templateName) {
// Modify $buffer
}
return $buffer;
}
}