In my layout.html.twig I have a navigation bar with some links. I want the links to be populated from a database.
For example, in the navigation bar I have a drop down of 'Recent Products'. How can I populate the dropdown in the main layout.html.twig from a database? (of course it'll be cached in the future)
Do I need to create a filter?
Any help would be great. Thanks
Note: In Symfony 1.4 I would have used a component. Does this exist in Symfony 2?
The answer is here: http://symfony.com/doc/2.0/book/templating.html#embedding-controllers
I needed to create a sub-controller and then embed the sub-controller view into the main twig layout.
Did you had a look @ the knplabs menu-bundle? https://github.com/knplabs/KnpMenuBundle
they are doing exactly what you want to… have look in the source to see how they achieve it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With