Zend_Navigation Tricks: True tab navigation with sub menus – Part 2
Part 2: Rendering the sub menus (relevant to the active tab).
This is where we employ another trick because the Zend_Navigation menu view helper does provide an option to render the active menu, but it is meant literally not the active branch of the menu like we’re trying to achieve.
In the layout we need to get the root level pages then we assume the 1st one is Home and root of all other navigation items. After this we loop through the pages below Home to find the active one and set this as the $nav2Container which we’ll use next.
layout.phtml
// find the active page/container under the rootPage (Home) for nav2 menu $rootPage = current($this->navigation()->getContainer()->getPages()); $pages = $rootPage->getPages(); foreach($pages as $page) { if($page->isActive(true)) { $nav2Container = $page; } }
Now that we know what the root of this sub menu should be we can use the helpers to render it (this is also in your layout file).
if(isset($nav2Container)) { echo $this->navigation()->menu()->renderMenu($nav2Container,array('ulClass' => 'nav2')); };