Updated the Bootstrap theme.
[yaffs-website] / web / themes / contrib / bootstrap / templates / 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 = item.url.getOption('container_attributes').class | split(" ")
26       %}
27       {%
28         set item_classes = [
29           item.is_expanded and item.below ? 'expanded dropdown',
30           item.in_active_trail ? 'active-trail',
31           loop.first ? 'first',
32           loop.last ? 'last',
33         ]
34       %}
35       <li{{ item.attributes.addClass(item_classes) }}>
36       {% if menu_level == 0 and item.is_expanded and item.below %}
37         <a{{ item.link_attributes.addClass(['dropdown-toggle', item.in_active_trail ? 'active-trail']) | without('data-toggle') }} href="{{ item.url }}" data-toggle="dropdown">{{ item.title }}<span class="caret"></span></a>
38       {% else %}
39         <a{{ item.link_attributes.addClass(item.in_active_trail ? 'active-trail') }} href="{{ item.url }}">{{ item.title }}</a>
40       {% endif %}
41       {% if item.below %}
42         {{ _self.menu_links(item.below, attributes.removeClass(classes), menu_level + 1, classes) }}
43       {% endif %}
44       </li>
45     {% endfor %}
46     </ul>
47   {% endif %}
48 {% endmacro %}
49
50 {#
51   Invoke the custom macro defined above. If classes were provided, use them.
52   This allows the template to be extended without having to also duplicate the
53   code above. @see http://twig.sensiolabs.org/doc/tags/macro.html
54 #}
55 {{ _self.menu_links(items, attributes, 0, classes ? classes : ['menu', 'menu--' ~ menu_name|clean_class, 'nav']) }}