what is the correct way to add a class to knp_menu's
root element <ul>
with twig?
i tried a 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
Try to
found here https://github.com/KnpLabs/KnpMenu/issues/166
Have not found a clean solution to pass params in view also. My solution in the
builder
class:$menu->setChildrenAttribute('id', 'boo') ->setChildrenAttribute('class', 'foo');
You can add it in your menu builder like..
Update
I just got a notification about this and found another way although it requires you to use a custom template to achieve it.
In your custom template you need to override the
list
block like..In this rather than use
knp_menu.attributes(listAttributes)
you pass in a array with your on-the-fly generatedlistAttributes.class
value. This attribute is generate by joiningoption.rootClass
(if it exists) withlistAttributes.class
(if it exists) as thelistAttributes.class
value.The
option.rootClass
value is reset to''
after use using{% set options = options|merge({'rootClass': '' }) %}
so that it is not added to every sub-menu.This will allow you to render your menu using..