The getSearchablePages
hook is triggered when the the search index is rebuilt.
It passes the array of pages and the ID of the root page as arguments and
expects an array of absolute URLs as return value.
Using the getSearchablePages
hook is deprecated since Contao 4.11 and will no longer work in Contao 5.0. Use the
contao.sitemap
event instead.
array $pages
List of absolute URLs that should be indexed.
int $rootId
ID of the current root page. This parameter is not always available.
bool $isSitemap
true
if the hook is triggered when updating XML sitemap. This parameter is
not always available.
string $language
Language of the generated root page. This parameter is not always available.
Return the list of pages that should be indexed. Be aware that this means
these URLs will be requested, and each page is responsible for its indexing. By
checking $isSitemap
, you can decide wether to include your pages in the XML
sitemap or only for the search index.
// src/EventListener/GetSearchablePagesListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('getSearchablePages')]
class GetSearchablePagesListener
{
public function __invoke(array $pages, $rootId = 0, bool $isSitemap = false, string $language = null): array
{
// Modify the $pages array …
return $pages;
}
}