getPageIdFromUrl
Details
This page shows version 4.x. The current version can be found here.
The getPageIdFromUrl hook is triggered when the URL fragments are evaluated.
It passes the array of URL fragments as argument and expects an array of URL
fragments as return value.
The first fragment returned will usually be the ID or alias of a Contao page.
Note
Using the getPageIdFromUrl hook has been deprecated and will no longer work in Contao 5.0.
Parameters
array
$fragmentsThe URL fragments (current url exploded by slash). Be aware that previous hook callbacks could have modified this data.
Return values
Return the (modified) array of URL fragments.
Example
// src/EventListener/GetPageIdFromUrlListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('getPageIdFromUrl')]
class GetPageIdFromUrlListener
{
public function __invoke(array $fragments): array
{
// Analyze the fragments
if (…) {
\Contao\Input::setGet('myFirstCustomGetParameter', $fragments[1]);
\Contao\Input::setGet('mySecondCustomGetParameter', $fragments[2]);
return [$fragments[0]];
}
return $fragments;
}
}