menu.html.twig 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation 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. * @ingroup themeable
  21. */
  22. #}
  23. {% import _self as menus %}
  24. {%
  25. set classes = [
  26. 'sous-liste',
  27. ]
  28. %}
  29. {%
  30. set ulClasses = [
  31. 'ul1',
  32. 'ul2'
  33. ]
  34. %}
  35. {#
  36. We call a macro which calls itself to render the full tree.
  37. @see https://twig.symfony.com/doc/1.x/tags/macro.html
  38. #}
  39. {{ menus.menu_links(items, attributes, 0) }}
  40. {% macro menu_links(items, attributes, menu_level) %}
  41. {% import _self as menus %}
  42. <div class="menuOpen">
  43. {% if items %}
  44. {% if menu_level == 0 %}
  45. <ul{{ attributes.addClass(ulClasses, 'ul1') }}{{attributes.removeClass(classes, 'sous-liste')}}{{ attributes }}>
  46. {% else %}
  47. <ul{{ attributes.addClass(ulClasses, 'ul2') }}{{attributes.removeClass(classes, 'sous-liste')}}{{ attributes }}>
  48. {% endif %}
  49. {# <div{{ attributes.addClass('sous-liste') }}{{attributes.removeClass(ulClasses, 'ul1')}}> #}
  50. {% for item in items %}
  51. <div{{ attributes.addClass('sous-liste') }}{{attributes.removeClass(ulClasses)}}>
  52. <li{{ item.attributes }}>
  53. {{ link(item.title, item.url) }}
  54. {% if item.below %}
  55. {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
  56. {% endif %}
  57. </li>
  58. </div>
  59. {% endfor %}
  60. {# </div> #}
  61. </ul>
  62. {% endif %}
  63. </div>
  64. {% endmacro %}