views:

247

answers:

1

I am rendering the top-level elements of a Zend Navigation object in one place like this:

echo $this->navigation()->menu()->setMaxDepth(0);

How do I render the navigation tree from the second level on down for the active branch? I've tried creating a partial that loops the $this->container object, but I don't know how to determine if my current item is the active branch. Once I've determined that it's the active branch how do I render the menu? Am I doing this the hard way and missing something obvious?

Thanks!


UPDATE:

I accepted a solution because that's what I used, but I also would like to provide the answer to my actual question, for reference sake. ($this is the view object)

// Find the active branch, at a depth of one
$branch = $this->navigation()->findActive($this->nav, 1, 1);
if (0 == count($branch)) {
    // no active branch, find the default branch
    $pages = $this->nav->findById('default-branch')->getPages();
} else {
    $pages = $branch['page']->getPages();
}
$this->subNav = new Zend_Navigation($pages);

$this->subNav can then be used to render the sub-menu.

+1  A: 

I do something similar. My main navigation is handled with something like this...

$this->navigation()->menu()->setPartial('tabs.phtml');
echo $this->navigation()->menu()->render();

Then in my tabs.phtml I iterate over the container like so...

if (count($this->container)) {
  foreach($this->container as $page) {
    if ($page->isVisible()) {
      if ($page->isActive(true)) {
        $subcontainer = $page->getPages();
        foreach($subcontainer as $subpage) {
          // echo my link
        }
      }
    }
  }
}

I hope that helps a bit.

Inkspeak
The key I was missing is the `true` value for the `isActive()` function. It makes the function recursive.
Sonny
@Sonny, Always something simple, isn't it?!
Inkspeak