Contao Summit 2026 in Leipzig 15th and 16th October

getFrontendModule

The getFrontendModule hook allows to manipulate the generation of the front end modules.

Note

This hook is also executed for forms that are integrated into a page layout via a front end module.

Parameters

  1. \Contao\ModuleModel $model

    Database result of the front end module as a \Contao\ModuleModel instance.

  2. string $buffer

    The generated front end module buffer.

  3. object $module

    An instance of the front end module’s class that is registered for this module’s type.

Return Values

Return $buffer or your custom modification.

Example

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

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\Form;
use Contao\Module;
use Contao\ModuleModel;

#[AsHook('getFrontendModule')]
class GetFrontendModuleListener
{
    public function __invoke(ModuleModel $model, string $buffer, object $module): string
    {
        // Wrap a specific module in an additional wrapper div
        if (2 === (int) $model->id) {
            return '<div class="module">' . $buffer . '</div>';
        }

        return $buffer;
    }
}

References