One of the biggest problems with Zend_Navigation helpers is using partials to render sub-menus in order to achieve customized rendering especially when additional properties have been defined.
The approach to the solution is as follows:
// find the first active menu item
$subnav = $this->navigation()->menu()->findOneByActive(1);
// The finder methods return null for no matches so nee to check that
if ($subnav != null) {
// render the matched menu using a partial
echo $this->navigation()->menu()->renderPartial($subnav, 'index/customsubmenu.phtml');
}
Hello.
Will you tell me the reason the below code doesn’t work and how to improve it?
echo $this->navigation()->menu()
->setMinDepth(1)
->setMaxDepth(1)
->setRenderParents(false)
->setOnlyActiveBranch(true)
->renderPartial(null, array(‘partials/menu.phtml’, ‘default’));
Sorry, I mean how to use findOneByActive(…) to obtain the same as using set{Min/Max}Depth()?
Thomas,
I am not sure why your code may not be working, as the way the actual data is set-out may be an issue. My approach is to have unique top-level menus, to which all matching is done with the child menus being duplicated across the different parent menus as the need arises.
You need to check your data and the way the menus are defined, hope this helps
Stephen