byu_theme-8.x-4.x-dev/templates/includes/menu.html.twig
templates/includes/menu.html.twig
{#
/**
* @file
* Default theme implementation to display a menu.
*
* Available variables:
* - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item.
* - below: The menu item child items.
* - title: The menu link title.
* - url: The menu link url, instance of \Drupal\Core\Url
* - localized_options: Menu link localized options.
*
* @ingroup templates
*
* Define a custom macro that will render all menu trees.
*/
#}
{% macro menu_links(items, attributes, menu_level, classes) %}
{% if items %}
{% for item in items %}
{%
set item_classes = [
item.is_expanded and item.below ? 'expanded',
item.is_expanded and menu_level == 0 and item.below ? 'dropdown',
item.in_active_trail ? 'active',
]
%}
{% if menu_level == 0 and item.is_expanded and item.below %}
<a href="{{ item.url }}" class="dropdown-toggle" data-toggle="dropdown">
{{ item.title }} <span class="caret"></span>
{% else %}
{{ link(item.title, item.url) }}
{% endif %}
{% if item.below %}
{{ _self.menu_links(item.below, attributes.removeClass(classes), menu_level + 1, classes) }}
{% endif %}
</a>
{% endfor %}
{% endif %}
{% endmacro %}
{#
Invoke the custom macro defined above. If classes were provided, use them.
This allows the template to be extended without having to also duplicate the
code above. @see http://twig.sensiolabs.org/doc/tags/macro.html
#}
{{ _self.menu_links(items, attributes, 0, classes ? classes : ['menu', 'menu--' ~ menu_name|clean_class, 'nav']) }}
