sylius/twig-hooks
Sylius Twig Hooks is a lightweight component from the Sylius Stack initiative that adds a hook-based extension system for Twig templates, making it easier to customize and extend views in a structured, decoupled way.
laravel/tinker or spatie/laravel-twig).header vs. site_header) can lead to unintended overrides.Twig_Test_Environment).@stack/@push (simpler, built-in).before_content, after_sidebar) in a non-critical template.{% include 'partials/header.html.twig' %}) with hooks.{% if user.is_admin %}...{% endif %}) to hook-based registration.{% debug %} to inspect hook context.{{ hook_exists('footer') }}).twig/twig:v2.12.require sylius/twig-hooks:^1.0.Twig\Extension\AbstractExtension).$twig->addExtension(new \Sylius\TwigHooks\TwigHooksExtension());
$twig->setCache(false); // Disable if using hooks dynamically
spatie/laravel-twig or manual setup).base.html.twig with hook placeholders).AppServiceProvider:
public function boot(): void {
$twig = $this->app['twig'];
$twig->addExtension(new \Sylius\TwigHooks\TwigHooksExtension());
}
{# base.html.twig #}
<body>
{% hook 'header' %}
{% hook 'content' %}
{% hook 'footer' %}
</body>
$twigHooks->addHook('header', new \Twig\Markup('<nav>Dynamic Header</nav>', 'UTF-8'));
TwigHooksExtension).HOOKS.md file (name, purpose, examples).header_v2) for backward compatibility.\Sylius\TwigHooks\TwigHooksExtension::enableDebugMode();
twig/extra-bundle) to inspect hook execution.php artisan twig:hooks:list
footer hook if {% hook 'footer' %} exists).$hookCache = new \Symfony\Component\Cache\Adapter\ArrayAdapter();
$twigHooks->setCache($hookCache);
How can I help you explore Laravel packages today?