The generatePage hook is triggered before the main layout (fe_page) is compiled. It passes the page object, the layout object and a self-reference as arguments and does not expect a return value.


  1. \Contao\PageModel $pageModel

    The current page object.

  2. \Contao\LayoutModel $layout

    The active page layout applied for rendering the page.

  3. \Contao\PageRegular $pageRegular

    The current page type object.


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

use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\PageRegular;
use Contao\LayoutModel;
use Contao\PageModel;
use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface;

class GeneratePageListener implements ServiceAnnotationInterface
     * @Hook("generatePage")
    public function onGeneratePage(PageModel $pageModel, LayoutModel $layout, PageRegular $pageRegular): void
        // Do something …