8

I am using a navigation XML file in conjunction with my Zend Framework MVC app.

A top level menu is rendered at the top of my layout. The code to produce it looks like this:

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

This will automatically render an unordered list of links that I have styled into my top menu. Now, I want to render the submenu (to render the active container tree) taking advantage of all the built-in Zend_Navigation goodness (MVC and ACL integration) but with custom markup. I would do this by inserting this:

$this->navigation()->menu()->renderSubMenu();

In fact, I have a very specific set of markup that I need to render this with. It is so drastically different I do not think I could style an unordered list to accomodate my desired presentation.

Is there a simple way (or complicated if need be ;) to customize a submenu?

2 Answers 2

11

Check out this answer of mine: Getting Zend_Navigation menu to work with jQuery's Fisheye

Summarized, you create a view for the navigation and loop through the pages and use the page methods to create custom markup. As far as I know, there's no decorator-like support for Navigation currently.

Sign up to request clarification or add additional context in comments.

Comments

7

Typeoneerror put me on the right track, here is the code I ended up using:

In layout.phtml:

<?= $this->navigation()->menu()->renderMenu(null,array('maxDepth'   =>  0)); ?>
<? $this->navigation()->menu()->setPartial('sidemenu.phtml'); ?>
<?= $this->navigation()->menu()->render(); ?>

In sidemenu.phtml:

$this->navigation()->findByResource(
  Zend_Controller_Front::getInstance()->getRequest()->module .
  Zend_Controller_Front::getInstance()->getRequest()->controller
 );

 foreach ($this->container as $page) {
    if ($page->isVisible() && $this->navigation()->accept($page)) {
        if ($page->isActive()) {
            echo $page->getLabel();
            $subcontainer = $page->getPages();
            foreach ($subcontainer as $subpage) {
                echo $subpage->getLabel();
            }
        }
    }
 }

Worked like a charm, leaving this as an answer for someone else to find.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.