4
votes

I have a number of navigation menus within my layout. A main menu and a sub-menu.

When clicking on an item on the main menu it shows which item is Active. When loading a page in a sub menu, the main menu loses it's context and doesn't show which item is active.

I have configured my navigation using an XML config file, and this is being read in my Bootstrap.php

$navContainerConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'home');
$navContainer = new Zend_Navigation($navContainerConfig);
$this->view->navigation($navContainer);

$layout = $this->bootstrap('layout')->getResource('layout');
$layout->getView()->navigation($navContainer);

Then in my controller I generate a subtree menu:

$subTree = $this->view->navigation()->findOneById('settings_index');
$this->view->subTree = $subTree;

In my layout I have the main nav, and the subtree shown:

//main menu
echo $this->navigation()->menu()->renderMenu(null,array('maxDepth'   =>  0));

// ... some stuff ....

//subtree menu
echo $this->navigation()->menu()->renderMenu($this->subTree,array('maxDepth' => 0,'ulClass'=>'nav_sub'));

How do I display a submenu in my layout without the main menu losing it's context?

1
What do you mean by main menu losing it's context? So, by removing the subtree echo statement, it already works?user228395
sorry, what I mean is that it doesn't highlight which menu item is active.Jonny White

1 Answers

0
votes

Try next

// main menu
echo $this->navigation()->menu()->renderMenu(null,array('maxDepth'   =>  0));

// sub menu
echo $this->navigation()->menu()->renderMenu(null,array('minDepth' => 1, 'maxDepth'   =>  1));

Both menus should have proper "active" class.