compileArticle

The compileArticle hook is triggered after the article module has been compiled. It passes the template object, the module configuration, and the module object as arguments and does not expect a return value. It can be used e.g. to add additional data to the template.

Parameters

  1. \Contao\FrontendTemplate $template

    The current front end template instance for the article module

  2. array $data

    An associative array with the module configuration

  3. \Contao\Module $module

    The current module instance

Example

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

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\Module;
use Contao\FrontendTemplate;

#[AsHook('compileArticle')]
class CompileArticleListener
{
    public function __invoke(FrontendTemplate $template, array $data, Module $module): void
    {
        $template->customContent = '<p>This will be available in mod_article.html5 via $this->customContent</p>';
    }
}

References