getSearchablePages
Details
This page shows version 4.x. The current version can be found here.
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.
Note
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.
Parameters
array
$pagesList of absolute URLs that should be indexed.
int
$rootIdID of the current root page. This parameter is not always available.
bool
$isSitemaptrueif the hook is triggered when updating XML sitemap. This parameter is not always available.string
$languageLanguage of the generated root page. This parameter is not always available.
Return Values
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.
Example
// 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;
}
}- \Contao\Calendar#L287-L380
- \Contao\ModuleFaq#L21-L114
- \Contao\News#L252-L345
- \Contao\Newsletter#L955-L1047