outputFrontendTemplate

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.

Parameters

  1. string $buffer

    Content of the rendered front end template.

  2. string $template

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

Return Values

Return the original $buffer or override with your custom modification.

Example

// src/EventListener/OutputFrontendTemplateListener.php
namespace App\EventListener;

use Contao\CoreBundle\ServiceAnnotation\Hook;
use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface;

class OutputFrontendTemplateListener implements ServiceAnnotationInterface
{
    /**
     * @Hook("outputFrontendTemplate")
     */
    public function onOutputFrontendTemplate(string $buffer, string $template): string
    {
        if ($template === 'fe_page') {
            // Modify $buffer
        }

        return $buffer;
    }

References