The getRootPageFromUrl hook is triggered when searching the current root page. It does not pass any parameters and expects a \Contao\PageModel instance as return value or null.

Return Values

Return a \Contao\PageModel instance if you want to override the default method for searching the root page.


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

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

class GetRootPageFromUrlListener implements ServiceAnnotationInterface
     * @Hook("getRootPageFromUrl")
    public function onGetRootPageFromUrl(): ?\Contao\PageModel
        // Do something …