generateFrontendUrl
Details
This page shows version 4.x. The current version can be found here.
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.
Note
Using the generateFrontendUrl hook has been deprecated and will no longer work in Contao 5.0.
Parameters
array
$pageThe result row from
tl_pageto generate the URL from.string
$paramsAdditional parameters to add between page alias and URL suffix.
string
$urlThe 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;
}
}