The parseArticles
hook is triggered when parsing news articles. It passes the
front end template, the current article and the news module instance as arguments
and does not expect a return value.
\Contao\FrontendTemplate $template
The front end template instance for the news article (e.g. news_full
).
array $newsEntry
The current news item database result.
\Contao\Module $module
The module instance (e.g. \Contao\ModuleNewsList
).
// src/EventListener/ParseArticlesListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\FrontendTemplate;
use Contao\Module;
use Contao\UserModel;
#[AsHook('parseArticles')]
class ParseArticlesListener
{
public function __invoke(FrontendTemplate $template, array $newsEntry, Module $module): void
{
// Remove the default "by …" from Contao
$template->author = UserModel::findByPk($newsEntry['author'])->name;
}
}