good day,
i have twig layout template contents of zf2 skeleton (zfctwig version) , want have dynamic main navigation using variable set in module.config.php.
layout.twig:
<div class="nav-collapse collapse"> <ul class="nav"> {% item in navigation %} <li {% if item.active %} class="active" {% endif %}> <a href="{{ url(item.route) }}"> {{ translate(item.name) }} </a> </li> {% endfor %} </ul> </div><!--/.nav-collapse -->
i pass using onbootstrap() method in module.php:
module.php:
$navigation = array( 'home' => array( 'name' => 'home', 'route' => 'home', ), 'profile' => array( 'name' => 'profile', 'route' => 'myroute', 'active' => true ), ); $view = $e->getapplication('application')->getmvcevent()->getviewmodel(); $view->navigation = $navigation;
the $navigation variable placed in module.config.php after got working.
this code works when i'm not using twig in template (e.g. layout.phtml no twig codes) when using above layout.twig, {{navigation}} empty.
i think should not using
$view = $e->getapplication('application')->getmvcevent()->getviewmodel();
since think returns default zf2 viewmodel , not twig version don't know how it's retrieved.
if not problem, doing wrong? , if got working, how can change active index of $navigation['profile'] false in 1 of controllers?
thank much!
update:
it seems nobody had experience same problem. doing wrong way? there better way this? goal create dynamic main menu , navigation can modified using settings inside module.config.php rather updating view file constantly. changing in specific controller not either since want global since main menu same on every page. searched web can't find way using twig.
$sm->get('zfctwigrenderer');
use code access twig renderer
example :
public function onbootstrap(mvcevent $e) { $zfctwigrenderer = $e->getapplication()->getservicemanager()->get('zfctwigrenderer'); }
Comments
Post a Comment