In the Symfony 2 project I'm working on we had to add the bread crumbs to every page. The knplabs menu bundle wasn't helping so we decided to go on our own.
To achieve this I decided to use a Twig macro. But how was suppose to recognize the right bread crumbs to show? _context was the answer I found in the deeps of the Internet.
In Twig every page has access to a variable called _context that stores the whole of what Twig knows for that page. That means all the variables you have passed to the template.
So you can pass it to the macro as a unique variable and access whatever you need to disguise in which page you are and create the right bread crumbs.
Twig is quite a powerful templating engine but some of its features are not very clear in the documentation, like this one.
I hope you will find this little tip useful.
Add new comment