You are here

menu--extras.html.twig in Menu Item Extras 8

Same filename and directory in other branches
  1. 8.2 templates/menu--extras.html.twig

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
    • content: The field item content.
    • 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.

File

templates/menu--extras.html.twig
View source
  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. * - content: The field item content.
  14. * - localized_options: Menu link localized options.
  15. * - is_expanded: TRUE if the link has visible children within the current
  16. * menu tree.
  17. * - is_collapsed: TRUE if the link has children within the current menu tree
  18. * that are not currently visible.
  19. * - in_active_trail: TRUE if the link is in the active trail.
  20. */
  21. #}
  22. {% import _self as menus %}
  23. {#
  24. We call a macro which calls itself to render the full tree.
  25. @see http://twig.sensiolabs.org/doc/tags/macro.html
  26. #}
  27. {{ menus.menu_links(items, attributes, 0) }}
  28. {% macro menu_links(items, attributes, menu_level) %}
  29. {% import _self as menus %}
  30. {% if items %}
  31. {% if menu_level == 0 %}
  32. <ul{{ attributes.addClass('menu', 'menu-level-' ~ menu_level) }}>
  33. {% else %}
  34. <ul class="menu menu-level-{{ menu_level }}">
  35. {% endif %}
  36. {% for item in items %}
  37. {%
  38. set classes = [
  39. 'menu-item',
  40. item.is_expanded ? 'menu-item--expanded',
  41. item.is_collapsed ? 'menu-item--collapsed',
  42. item.in_active_trail ? 'menu-item--active-trail',
  43. ]
  44. %}
  45. <li{{ item.attributes.addClass(classes) }}>
  46. {{ link(item.title, item.url) }}
  47. {% if item.below or item.content %}
  48. <div class="menu-level js-menu-level menu-dropdown-level-{{ menu_level }}">
  49. {% if item.content %}
  50. <div class="menu-item--content-extras">
  51. {{ item.content }}
  52. </div>
  53. {% endif %}
  54. {% if item.below %}
  55. {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
  56. {% endif %}
  57. </div>
  58. {% endif %}
  59. </li>
  60. {% endfor %}
  61. </ul>
  62. {% endif %}
  63. {% endmacro %}