generateFrontendUrl

The generateFrontendUrl hook is triggered when a front end URL is recreated. It passes the page object, the parameter string and the default URL as arguments and expects a string as return value.

Using the generateFrontendUrl hook has been deprecated and will no longer work in Contao 5.0.

Parameters

  1. array $page

    The result row from tl_page to generate the URL from.

  2. string $params

    Additional parameters to add between page alias and URL suffix.

  3. string $url

    The URL generated by Contao.

Return Values

A string containing the new (or previous) URL.

Example

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

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;

#[AsHook('generateFrontendUrl')]
class GenerateFrontendUrlListener
{
    public function __invoke(array $page, string $params, string $url): string
    {
        // Create or modify $url …

        return $url;
    }
}

References