我在 KnpMenuBundle 的导航栏菜单上写下了最后几天的内容。我只想简单地给模板一些参数,然后对其做出反应。是否可以?我试过这个:
$menu->addChild('Registration', array('route' => 'fos_user_registration_register',
'icon' => array('glyphicon' => 'briefcase')));
然后我想在 Twig 模板中选择这个:
{% if icon['glyphicon'] is defined %}
<span class="glyphicon glyphicon-{{icon['glyphicon']}} "></span>
{% endif %}
我尝试了很多,但没有任何效果。接下来我可以尝试什么?
我是这样做的
菜单类:
$menu->addChild('Home', array(
'route' => 'home',
'extras' => array('icon' => 'home')
));
我的菜单在模板中调用,我要求一个特定的树枝模板
{{ knp_menu_render('MyBundle:Menu:primaryNav', {'template': 'MyBundle:Menu:primaryNav.html.twig'}) }}
在树枝模板中,我复制/粘贴 knpmenubundle 模板并编辑一些块。您也可以使用“扩展”和模板的继承内容来做到这一点(可能是一个更好的主意)。
图标编辑块的示例:
{% block spanElement %}
<a href="#" class="dropdown-toggle">
{% if item.extras.icon is defined %}<i class="icon-{{ item.extras.icon }}"></i>{% endif %}
<span class="menu-text"> {{ block('label') }}</span>
<b class="arrow icon-angle-down"></b>
</a>
{% endblock %}
您需要的可能是菜单类中的这个“附加”字段:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)