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.
array $page
The result row from tl_page
to generate the URL from.
string $params
Additional parameters to add between page alias and URL suffix.
string $url
The URL generated by Contao.
A string containing the new (or previous) URL.
// 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;
}
}