I am desperately trying to render a submenu in symfony-cmf.
Example
Structure:
page1
├─p1-subpage1
├─p1-subpage2
└─p1-subpage3
page2
├─p2-subpage1
└─p2-subpage2
Whenever the current page is somewhere within the page1
hierarchy it should use p1-subpage*
to render the menu, when I am within the page2
hierarchy it should use p2-subpage*
to render the menu. Technically that means it should set the current item to the parent of the 1st level (if it's not already on it) and render one level of nodes (e.g. knp_menu_render('main', { depth: 1 })
).
The problem can be split in two parts:
- Rendering a (sub-)menu from a given node
- Retrieving the current node
Thoughts and Trials
- TWIG: It has been suggested to support rendering submenus as a functionality of the KnpMenu itself, but it hasn't been done. As a workaround registering a twig extension has been provided by someone in the issue. However this extension is based on the
getCurrentItem
Method which has been removed with KNP-Menu 2.0. Although the cmf currently uses v1.1 of the knp-menubundle, this is going to change soon - TWIG: The CnertaBreadcrumbBundle would bring back this functionality, but depends on KNP-Menu 2.0 as well.
- TWIG: Using a hack similar as suggested here. It checks the current URI, counts the number of slashes and decides based on that what to use. This could probably work. Problem here: I don't have
cmfMainContent
variable defined, nor can I find anything similar in my{{ dump() }}
(nothing containig a menu either). - RouteVoter: The cmf itself has some MenuVoters itself, which are well documented what they are, but not how to use them. I don't think that there is any way to access that functionality whithin twig nor do I know how to intercept the menu building.
Thanks for any help.