loadPageDetails

This feature is only available in Contao 4.8 and later.

This hook is executed whenever the details of a page are loaded via \Contao\PageModel::loadDetails. This hook allows you to add additional details to the \Contao\PageModel instance.

Parameters

  1. array $parentModels

    An array containing all the parent pages of the processed page.

  2. \Contao\PageModel $page

    The processed page for which the details are added.

    // src/EventListener/LoadPageDetailsListener.php
    namespace App\EventListener;
    
    use Contao\CoreBundle\ServiceAnnotation\Hook;
    use Contao\PageModel;
    use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface;
    
    class LoadPageDetailsListener implements ServiceAnnotationInterface
    {
    /**
     * @Hook("loadPageDetails")
     */
    public function onLoadPageDetails(array $parentModels, PageModel $page): void
    {
        // Add some additional date from the root page to the processed page
        if (count($parentModels) > 0) {
            $rootPage = end($parentModels);
            $page->myCustomVariable = $rootPage->myCustomRootVariable;
        }
    }
    }
    

References