php - Add Class to knp menu root Element with Twig -
what right way add together class knp_menu's
root element <ul>
twig?
i tried lot of things:
1.
{{ knp_menu_render('main', {'class': 'foo'}) }}
2.
{{ knp_menu_render('main', {'attributes': {'class': 'foo'}}) }}
3.
{{ knp_menu_render('main', {'listattributes': {'class': 'foo'}}) }}
4.
{{ knp_menu_render('main', {'attributes': {'listattributes': {'class': 'foo'}}}) }}
none of them worked
you can add together in menu builder like..
$menu = $this->factory->createitem('root', array( 'childrenattributes' => array( 'class' => 'foo', ), ));
update
i got notification , found way although requires utilize custom template accomplish it.
in client template need override list
block like..
{% block list %} {% if item.haschildren , options.depth not sameas(0) , item.displaychildren %} {% import _self knp_menu %} <ul{{ knp_menu.attributes(listattributes|merge({'class': [ options.rootclass defined ? options.rootclass : '', listattributes.class defined ? listattributes.class : '' ]|join(' ') })) }}> {% set options = options|merge({'rootclass': '' }) %} {{ block('children') }} </ul> {% endif %} {% endblock %}
in rather utilize knp_menu.attributes(listattributes)
pass in array on-the-fly generated listattributes.class
value. attribute generate joining option.rootclass
(if exists) listattributes.class
(if exists) listattributes.class
value.
the option.rootclass
value reset ''
after utilize using {% set options = options|merge({'rootclass': '' }) %}
not added every sub-menu.
this allow render menu using..
{{ knp_menu_render('main', {'rootclass': 'foo' }) }}
php symfony2 twig knpmenubundle
No comments:
Post a Comment