Skip to content

Instantly share code, notes, and snippets.

@mariohernandez
Last active June 3, 2019 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariohernandez/e0d4c43c9b59df20c9492462d3721499 to your computer and use it in GitHub Desktop.
Save mariohernandez/e0d4c43c9b59df20c9492462d3721499 to your computer and use it in GitHub Desktop.
{#
/**
* @file
* Theme override 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.
* - is_expanded: TRUE if the link has visible children within the current
* menu tree.
* - is_collapsed: TRUE if the link has children within the current menu tree
* that are not currently visible.
* - in_active_trail: TRUE if the link is in the active trail.
*/
#}
{% import _self as menus %}
{{ menus.main_menu(items, attributes, 0) }}
{% macro main_menu(items, attributes, menu_level) %}
{% import _self as menus %}
{% if items %}
{% if menu_level == 0 %}
<ul{{ attributes.addClass('main-menu__list') }}>
{% else %}
<ul class="main-menu__submenu">
{% endif %}
{% for item in items %}
<li class="main-menu__item main-menu__item--level-{{ menu_level }}
{{- item.is_active_trail ? 'main-menu__item--active-trail' -}}">
<a href="{{ item.url }}" class="main-menu__link">
{{ item.title }}
</a>
{% if item.below %}
{{ menus.main_menu(item.below, attributes, menu_level + 1) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment