4 * Default theme implementation to display a menu.
7 * - menu_name: The machine name of the menu.
8 * - items: A nested list of menu items. Each menu item contains:
9 * - attributes: HTML attributes for the menu item.
10 * - below: The menu item child items.
11 * - title: The menu link title.
12 * - url: The menu link url, instance of \Drupal\Core\Url
13 * - localized_options: Menu link localized options.
17 * Define a custom macro that will render all menu trees.
20 {% macro menu_links(items, attributes, menu_level, classes) %}
22 <ul{{ attributes.addClass(menu_level == 0 ? classes : 'dropdown-menu') }}>
23 {% for item in items %}
26 item.is_expanded and item.below ? 'expanded',
27 item.is_expanded and menu_level == 0 and item.below ? 'dropdown',
28 item.in_active_trail ? 'active',
31 {% if menu_level == 0 and item.is_expanded and item.below %}
32 <li{{ item.attributes.addClass(item_classes) }}>
33 <a href="{{ item.url }}" class="dropdown-toggle" data-toggle="dropdown">{{ item.title }} <span class="caret"></span></a>
35 <li{{ item.attributes.addClass(item_classes) }}>
36 {{ link(item.title, item.url) }}
39 {{ _self.menu_links(item.below, attributes.removeClass(classes), menu_level + 1, classes) }}
48 Invoke the custom macro defined above. If classes were provided, use them.
49 This allows the template to be extended without having to also duplicate the
50 code above. @see http://twig.sensiolabs.org/doc/tags/macro.html
52 {{ _self.menu_links(items, attributes, 0, classes ? classes : ['menu', 'menu--' ~ menu_name|clean_class, 'nav']) }}