Reputation: 1846
I extend my baselayout in every twig template like
{% extends 'someBundle::base.html.twig' %}
Now i need some stuff to do on the mainpage and therefor i need a controller that is executed everytime the base.html.twig is loaded, so dont have to do this stuff in every single controller.
I have googled a lot but did not find anything. Don't know exactly what to search for.
I'm sure u know i mean, if not its no problem to explain further. Thanks in advance!
Upvotes: 0
Views: 40
Reputation: 13127
You can write a very simple Twig extension which provides a template function, which again you can embed into your base.html.twig
.
This way, each time base.html.twig
is loaded, the function is executed. As the Twig extension is basically a special type of service, you can pass it any dependencies you need.
Upvotes: 1