menu--main.html.twig

Public

For a certain menu item key, use links, classes, other markup

Get raw version
php
  1. {#
  2. /**
  3.  * @file
  4.  * Theme override 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.  * - is_expanded: TRUE if the link has visible children within the current
  15.  * menu tree.
  16.  * - is_collapsed: TRUE if the link has children within the current menu tree
  17.  * that are not currently visible.
  18.  * - in_active_trail: TRUE if the link is in the active trail.
  19.  */
  20. #}
  21. {% import _self as menus %}
  22.  
  23. {% set attributes = attributes.addClass('menu--dropdown menu--primary-menu') %}
  24.  
  25. {#
  26. We call a macro which calls itself to render the full tree.
  27. @see http://twig.sensiolabs.org/doc/tags/macro.html
  28. #}
  29. {{ menus.menu_links(items, attributes, 0) }}
  30.  
  31. {% macro menu_links(items, attributes, menu_level) %}
  32. {% import _self as menus %}
  33. {% if items %}
  34. {% if menu_level == 0 %}
  35. <ul{{ attributes.addClass('menu') }}>
  36. {% else %}
  37. <ul class="menu">
  38. {% endif %}
  39. {% for key, item in items %}
  40. {% set classes = [
  41. 'menu-item',
  42. item.is_expanded ? 'menu-item--expanded',
  43. item.is_collapsed ? 'menu-item--collapsed',
  44. item.in_active_trail ? 'menu-item--active-trail',
  45. ] %}
  46. <li{{ item.attributes.addClass(classes) }}>
  47. {% if key == 'menu_link_content:7b965e5c-7adb-45b3-93c5-61309729121a' %}
  48. <a href="#" class="icon-chevron">{{ item.title }}</a>
  49. {% elseif key == 'menu_link_content:03893a95-5be7-4805-a2c6-21df3e0bf0b9' %}
  50. <a href="{{ item.url }}" class="icon-search">
  51. <span class="h-vh">{{ item.title }}</span></a>
  52. {% else %}
  53. {{ link(item.title, item.url) }}
  54. {% endif %}
  55. {% if item.below %}
  56. {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
  57. {% endif %}
  58. </li>
  59. {% endfor %}
  60. </ul>
  61. {% endif %}
  62. {% endmacro %}
  63. <a href="#top" id="js-site-nav-close" class="site-nav-close"><span class="h-vh">Return to Content</span></a>