KnpLabs/KnpMenu — Issue #26: Displaying menu for a certain level in the tree
Author: petesiss
Created: 2012-02-06 15:09:10+00:00
State: open

No matter what level the current page is, I am displaying all the level 1 items across the top of the page, then all the level 2 items in a separate LHS col menu.

This doesn't seem to be straight forward as there is no helper to render a menu at a certain level, and no means to easily return e.g. the level 2 ancestor for the current page, in order to use this to create the menu.

Currently in order to achieve this, I am working up the provided breadCrumb array and testing for the level at each point, only rendering the LHS menu when I find the ancestor with the required level.

This is really messy in twig... clearly not the right way to go about it.

So I am wondering about whether to add methods to the menuItems class to return information regarding ancestors.

e.g. would it be useful to have

/**
* @param int $level The level of the ancestor to be returned
* @return \Knp\Menu\ItemInterface
*/
public function getAncestor($level)
{
}

Any thoughts?

Is there already an accepted way to do this kind of thing?