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

  1. string $buffer

    Content of the parsed front end template.

  2. string $template

    The template name (e.g. nav_default) without file extension.

  3. since 4.9.21 \Contao\FrontendTemplate $template

    The 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;
    }
}

References