Step 1:- Goto + Configure block + click
Step 2:- Goto + Menu levels + click to check box Expand all menu items
Like
And save
Step 3:- I have A Hmtl
Step 4:- Add the class in twig file
We have a twig file
Menu.html.twig
Step 5: override the twig file and add the class of the file
Code:-
{% import _self as menus %}
{#
We call a macro which calls itself to render the full tree.
@see http://twig.sensiolabs.org/doc/tags/macro.html
#}
{{ menus.menu_links(items, attributes, 0) }}
{% macro menu_links(items, attributes, menu_level) %}
{% import _self as menus %}
{% if items %}
{% if menu_level == 0 %}
<ul{{ attributes.addClass('menu', 'nav', 'navbar-nav') }}>
{% else %}
<ul{{ attributes.addClass('dropdown-menu') }}>
{% endif %}
{% for item in items %}
{% if menu_level == 0 and item.is_expanded %}
<li{{ item.attributes.addClass('expanded', 'dropdown') }}>
<a href="{{ item.url }}" class="dropdown-toggle" data-target="#" data-toggle="dropdown">{{ item.title }} <span class="caret"></span></a>
{% else %}
<li{{ item.attributes }}>
{{ link(item.title, item.url) }}
{% endif %}
{% if item.below %}
{{ menus.menu_links(item.below, attributes.removeClass('nav', 'navbar-nav'), menu_level + 1) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
No comments:
Post a Comment
If you have any problem please let me know.