You are here

menu--simple-megamenu.html.twig in Simple Mega Menu 2.0.x

Same filename and directory in other branches
  1. 8 templates/menu--simple-megamenu.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
    • 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--simple-megamenu.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. * - 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. We call a macro which calls itself to render the full tree.
  24. @see http://twig.sensiolabs.org/doc/tags/macro.html
  25. #}
  26. {{ attach_library('simple_megamenu/base') }}
  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--simple-mega-menu') }}>
  33. {% else %}
  34. <ul {{ attributes.removeClass('menu--simple-mega-menu') }}>
  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 %}
  48. {% if has_megamenu(item.url) %}
  49. <div class="mega-menu-wrapper">
  50. <div class="mega-menu-background"></div>
  51. {{ view_megamenu(item.url, 'before') }}
  52. {{ menus.menu_links(item.below, attributes.addClass('mega-menu-item'), menu_level + 1) }}
  53. {{ view_megamenu(item.url, 'after') }}
  54. </div>
  55. {% else %}
  56. {{ menus.menu_links(item.below, attributes.removeClass('mega-menu-item'), menu_level + 1) }}
  57. {% endif %}
  58. {% endif %}
  59. </li>
  60. {% endfor %}
  61. </ul>
  62. {% endif %}
  63. {% endmacro %}