I am using MenuBundle to do exactly this. If you follow the documentation and create a MainMenu class and include it in a template, then within a controller you can access the menu and tell it which menu item should be current. This way the current item is set before the menu is rendered. For example, this might be in a controller action:
$menu = $this->get('menu.main'); $menu->getChild("MyMenuItem")->setIsCurrent(true); I do this because i have an action mapped to a long route like this: / {1}/{2}/{3}/{4} and MenuBundle can't figure out if the menu item should be current or not. hope this helps. On May 12, 12:41 pm, Carl <carl.par...@gmail.com> wrote: > I've been looking for a way to do something similar. I want to highlight a > menu item if the user is in a particular category on the site. I use the > Knplabs MenuBundle for menus on my site but it uses the full URL for > checking to see if it should highlight a particular menu item. Without > adding custom code to parse each URL and matching it against an existing > list of sections you've defined somewhere in your application, I'm not sure > how else you'd be able to do this at the moment. I don't think it's possible > to directly get the controller name in a template. If it is, I'm curious how > to do it as well. > > If you use MenuBundle, you can write your own custom MenuItem classes and > can choose how to render each piece of the menu. So you can prepare your > menus using that and then only worry about rendering them in your templates. > You may want to check it out if you haven't already. It's saved me a lot of > time. > > https://github.com/knplabs/MenuBundle/ -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en