getArticles

The getArticles hook allows you to replace a column’s articles with custom content. It passes the page ID and the requested column (e.g. 'main') as arguments. It expects a string as return value or null. If a string is returned, no further hooks of the same type are executed and that content will be shown in the front end.

Parameters

  1. int $pageId

    The articles’ parent page ID.

  2. string $column

    The column for which the articles are rendered.

Return Values

Return a string with the article’s new content or null to keep the default.

Example

// src/EventListener/GetArticlesListener.php
namespace App\EventListener;

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;

#[AsHook('getArticles')]
class GetArticlesListener
{
    public function __invoke(int $pageId, string $column): ?string
    {
        if (10 === (int) $pageId && 'main' === $column) {
            // Generate your custom articles content here
            return $customArticlesContent;
        }

        return null;
    }
}

References