1f48ae6638d2939864538f15ac8284b0d246862d
[yaffs-website] / menu / menu.html.twig
1 {#
2 /**
3  * @file
4  * Default theme implementation to display a menu.
5  *
6  * Available variables:
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.
14  *
15  * @ingroup templates
16  *
17  * Define a custom macro that will render all menu trees.
18  */
19 #}
20 {% macro menu_links(items, attributes, menu_level, classes) %}
21   {% if items %}
22     <ul{{ attributes.addClass(menu_level == 0 ? classes : 'dropdown-menu') }}>
23     {% for item in items %}
24       {%
25         set item_classes = [
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',
29         ]
30       %}
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>
34       {% else %}
35         <li{{ item.attributes.addClass(item_classes) }}>
36         {{ link(item.title, item.url) }}
37       {% endif %}
38       {% if item.below %}
39         {{ _self.menu_links(item.below, attributes.removeClass(classes), menu_level + 1, classes) }}
40       {% endif %}
41       </li>
42     {% endfor %}
43     </ul>
44   {% endif %}
45 {% endmacro %}
46
47 {#
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
51 #}
52 {{ _self.menu_links(items, attributes, 0, classes ? classes : ['menu', 'menu--' ~ menu_name|clean_class, 'nav']) }}