1


As you can read from the title, I'm trying to add class="current" part to the HTML anchor tag that my zend_navigation renders.

Here's what i have:

Bootstrap.php

protected function _initNavigation(){
         $this->bootstrap('layout');
         $layout = $this->getResource('layout');
         $view = $layout->getView();
         $config = new Zend_Config_Xml(APPLICATION_PATH .'/configs/navigation.xml','nav');
         $navigation = new Zend_Navigation($config);
         $navigation->current()
         $view->navigation($navigation);
     } 

And then in the View script:

<div class="NavMenu">
  <?= $this->navigation()->menu(); ?>
</div>

I’m pretty sure there’s some standard and proper way of doing it, but after about couple hours of search, I’m unable to find my answer. Many thanks to you for your kind help.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
Still Questioning
  • 670
  • 2
  • 7
  • 23

2 Answers2

5

Stick this in your controller...

public function init()
{
            $uri = $this->_request->getPathInfo();          
            $activeNav = $this->view->navigation()->findByUri($uri);
            $activeNav->active = true;
            $activeNav->setClass("active");
}

For more information read the comments of the setClass method in Zend_Navigation_Page

http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Navigation/Page.php

mapsi
  • 644
  • 6
  • 13
0

You could create your own menu view partial or if you're only interested in targeting links under the active menu item, try

li.active > a

in your CSS.

Phil
  • 157,677
  • 23
  • 242
  • 245
  • Hi Phil, Thank you for the response! is there any way you can show what the view partial could look like? I'm new to ZF and in desperate need of help. I've spend the whole day today searching..and trying just to highlight the menu tab that is the user on...but no luck so far.. – Still Questioning Dec 03 '10 at 04:04
  • @Mandaa The default menu helper sets an "active" class on the `
  • ` element parent(s) of the current page. You can use this in your CSS to highlight the current menu item. Otherwise, look at the menu helper source to get an idea about how to build your own view partial.
  • – Phil Dec 03 '10 at 04:15