3

I've posted an edit to my question. While working on it I noticed the problem is easy to simplify. I need a custom format of my submenu so i have to use partial. But then the problem occurs.

The below code shows the INCORRECT level (0):

            echo $this->navigation()->menu()
                ->setMinDepth(1)
                ->setMaxDepth(1)
                ->setRenderParents(false)
                ->setOnlyActiveBranch(true)
                ->renderPartial(null, array('partials/menu.phtml', 'default'));

The below code shows the CORRECT menu level (1)

            echo $this->navigation()->menu()
                ->setMinDepth(1)
                ->setMaxDepth(1)
                ->setRenderParents(false)
                ->setOnlyActiveBranch(true)
                ->render();

Any ideas? Guys please. I would appreciate any help!

Edit

My partials/menu.phtml:

    foreach ($this->container as $page) 
{
    $active = $page->isActive();
    echo '<div class="item">';
        echo '<a class="'. ($active ? 'active' : '') .'" href="' . $this->baseUrl($page->getHref()) . '">' . $page->getLabel() . '</a>';
    echo '</div>';
}

EDIT 2

My understanding of Zend_Navigation was, first to prepare container and than put it through partial.

            $nav = $this->navigation()->menu()->setOnlyActiveBranch(true)->getContainer();
        echo $this->navigation()->menu()->renderPartial($nav, array('/partials/menu.phtml', 'default'));

What is the point of setting set{Min/Max}Depth, parentRendering at the container when passing it anywehere is useless?

dbq
  • 111
  • 2
  • 11
  • What does your partial actually do? All those options for menu helper don't actually get passed to the partial, you just get the Navigation container. – John Flatness Oct 16 '12 at 00:55
  • Partial does all the formatting. I can't use UL tag, need custom html markup. I thought partial was just the step to change the rendering with respect to minDepth, maxDepth, renderParents etc. Any ideas how to combine it? I posted example partial. – dbq Oct 16 '12 at 07:31

3 Answers3

1

I use this code:

<?=$this->navigation()->menu()->renderPartial(null, 'shared/menu.phtml')?>

you should pass true to the method $page->isActive(true) so that also functions in depth.

in your partial

foreach ($this->container as $page) {
  $active = $page->isActive(true);
  if (count($page->getPages())) {
    foreach ($page->getPages() as $subPage) {
      $active = $subPage->isActive(true);
      echo '<div class="item">';
        echo '<a class="'. ($active ? 'active' : '') .'" href="' . $this->baseUrl($subPage->getHref()) . '">' . $subPage->getLabel() . '</a>';
      echo '</div>';      
    }
  }
}

before the second foreach you could add a check if and when to show the submenu.

my 2 cent.

EDIT

try this:

$partial = array('partials/menu.phtml', 'default');
echo $this->navigation()->menu()
  ->setMinDepth(1)
  ->setMaxDepth(1)
  ->setRenderParents(false)
  ->setOnlyActiveBranch(true)
  ->setPartial($partial)
  ->render();
JellyBelly
  • 2,451
  • 2
  • 21
  • 41
  • Still don't understand you well. Will you extend the possibilities you mean that would filter the submenu? I have no idea how to do it. 2 days spent on it. Please, have a look at my second edit. – dbq Oct 16 '12 at 10:14
  • I used it with my partial and it doesn't work. It shows the zero level, just like setting depths has no influence. – dbq Oct 16 '12 at 11:13
  • The above code doesn't work. Below, I give you render() from Zend library. Your code does exactly the same as mine. `public function render(Zend_Navigation_Container $container = null) { if ($partial = $this->getPartial()) { return $this->renderPartial($container, $partial); } else { return $this->renderMenu($container); } }` – dbq Oct 16 '12 at 11:41
0

Came across this while searching for an answer to the same problem. Having looked through the code for Zend_View_Helper_Navigation_Menu, it doesn't look like any of the view helper options are passed through to the view partial, although I don't see why they couldn't be... (in ZF 1.12 take look a line 736 of Zend_View_Helper_Navigation_Menu, the only thing passed is the container itself, the options array could easily be passed along with it, or the container prefiltered, may be worth filing a feature request with ZF)

These options are purely a way of filtering the Zend_Navigation_Container for rendering with the default renderMenu method. As you say, it seems you can accomplish the same thing by first filtering the container and then passing it as the first argument of the renderPartial method

baseten
  • 1,362
  • 1
  • 13
  • 34
0

In your main view

Find the container of the submenu located in navigation config. Then echo this container using said partial.

$pages = $this->navigation()->findOneBy('label', 'Label of your submenu');
echo $this->navigation()->menu()->renderPartial($pages,module/partials/menu.phtml');

In the partial (module/partials/menu.phtml)

Customise. This example iterates over the top level pages of your chosen container.

foreach ($this->container as $page) {
 echo $this->navigation()->menu()->htmlify($page) . PHP_EOL;
}
krk
  • 1
  • 2