Zend Framework 2 Navigation Sub-Sub menu -
Zend Framework 2 Navigation Sub-Sub menu -
say have next navigation:
home internal folders new folder configuration categories new tags new options new contact external
the code used in layout.phtml show menu:
$internal = $this->navigation('navigation')->findonebylabel('internal'); echo $this->navigation('navigation') ->menu() ->setulclass('nav nav-list') ->setmaxdepth(1) ->rendermenu($internal);
so shows this:
folders new folder configuration categories tags options contact
at moment i'm getting decent menu, showing parents , first childs, 'new' navigation never showing.
however, if i'm on page 'categories' want show childs too, 'new' under 'categories' should showing, following:
folders new folder configuration categories new tags options contact
i have tried many ways seek this, , have checked options (setmindepth, setmaxdepth, rendersubmenu, setparentmenu) can give menu in layout.phtml, without succes. it's either 'new' included, or not included, not in between.
the documentation zf2 not giving me how sub menu working, apart making partial.
so, making partial alternative this?
thanks in advance!
for little project while ago, have made quick fix. we've been planning clean code , create configurable, never project required same.
tl;dr: cannot utilize normal zf2 view helper have "top" level page want display (internals in case) , display menu below page.
<?php namespace application\view\helper; utilize zend\view\helper\abstracthelper; class subnavigation extends abstracthelper { public function __invoke($class = null) { $view = $this->getview(); $menu = $view->navigation()->menu(); $container = $view->navigation()->getcontainer(); $active = $view->navigation()->setrenderinvisible(true)->findactive($container); if (!$active) { return; } $container = $active['page']; $depth = $active['depth']; while (0 !== $depth) { $container = $container->getparent(); $depth--; } $visible = $container->isvisible(); $html = $menu->setcontainer($container->setvisible(true)) ->setulclass('') ->setonlyactivebranch(false) ->setmindepth(null) ->setmaxdepth(null) ->render(); $container->setvisible($visible); if (strlen($html)) { homecoming sprintf('<ul %s><li%s><a href="%s">%s</a>%s</li></ul>', (null !== $class) ? ' class="' . $class . '"' : null, ($container->isactive())? ' class="active"' : null, $container->gethref(), $container->getlabel(), $html); } } }
this view helper renders "internal" top menu-item in sprintf()
call, can alter behaviour. can echo $html
, it's need.
navigation zend-framework2
Comments
Post a Comment