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.

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\ServiceAnnotation\Hook;
use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface;

class ParseFrontendTemplateListener implements ServiceAnnotationInterface
{
    /**
     * @Hook("parseFrontendTemplate")
     */
    public function onParseFrontendTemplate(string $buffer, string $template): string
    {
        if ('ce_text' === $template) {
            // Modify $buffer
        }

        return $buffer;
    }
}

References