Rendering Active Branch of Zend Navigation Without Top Level

后端 未结 3 823
刺人心
刺人心 2021-01-15 12:50

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

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


        
相关标签:
3条回答
  • 2021-01-15 13:33

    If I got your question right, this is how I do it:

    print $this->navigation()->menu()->renderMenu(null, array(
        'minDepth' => 1,
        'maxDepth' => 1,
        'onlyActiveBranch' => true,
        'renderParents' => false));
    

    Renders only the submenu of currently active menu.

    0 讨论(0)
  • 2021-01-15 13:42

    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.

    0 讨论(0)
  • 2021-01-15 13:50

    I do it this way:

    <?php
    
    // Render top-level elements
    echo $this->navigation()->menu()->setMaxDepth(0);
    
    // Render 2nd level elements for active element
    echo $this->navigation()->menu()
            ->setOnlyActiveBranch(true)
            ->setRenderParents(false)
            ->setMinDepth(1);
    
    ?>
    

    but this is not a good solution. Better one for each level as a separate menu:

    <!-- level 1 -->
    <?php echo $this->navigation()->menu()->setMaxDepth(0); ?>
    
    
    <!-- level 2 -->
    <?php echo $this->navigation()->menu()->setOnlyActiveBranch(true)->setRenderParents(true)->setMinDepth(1)->setMaxDepth(1); ?>
    
    
    
    <!-- level 3 -->
    <?php echo $this->navigation()->menu()->setOnlyActiveBranch(true)->setRenderParents(false)->setMinDepth(2)->setMaxDepth(2); ?>
    
    0 讨论(0)
提交回复
热议问题