parseTemplate

The parseTemplate hook is triggered before parsing a template. It passes the template object and does not expect a return value.

Parameters

  1. Template $template

    The front end or back end template instance.

Example

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

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

class ParseTemplateListener implements ServiceAnnotationInterface
{
    /**
     * @Hook("parseTemplate")
     */
    public function onParseTemplate($template): void
    {
        if ('fe_page' === $template->getName()) {
            // Do something …
        }
    }
}

References