The parseBackendTemplate
hook is triggered when a back end template is parsed.
It passes the template content and the template name as arguments and expects
the template content as return value.
string $buffer
Content of the parsed back end template.
string $template
The template name (e.g. be_widget
) without file extension.
Return the original $buffer
or override with your custom modification.
// src/EventListener/ParseBackendTemplateListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('parseBackendTemplate')]
class ParseBackendTemplateListener
{
public function __invoke(string $buffer, string $template): string
{
if ('be_main' === $template) {
// Modify $buffer
}
return $buffer;
}
}