For a recent project, I needed to include KnpMenuBundle in a Symfony2 project. This project was styled using the famous Twitter Bootstrap. I’ve found many articles describing how to do this but all of them didn’t exactly resulted in something I wanted: a web application with a navigation bar including icons and dropdown menu’s. In addition, I needed a “active” class indicating which item was visited, including parent/child items.
The files below belong to a tutorial which can be found here: http://nielsmouthaan.nl/symfony2-knpmenubundle-font-awesome-twitter-bootstrap-integration-navigation-bar-including-icons-and-dropdown-menus/
Maybe some unrelated but you saved me nerves!
I was trying to find a away the see the menu active while browsering in sub-routes like /show/id etc.
Finally I ended up with your code and change a little row for my purpose which I wanted to share:
So I changed the / into !$this->container->get('router')->getContext()->getBaseUrl().'/ ' adding the baseUrl if not in main directory and adding simply /. So people who acutally have symfony not located in the root ;)