templates/Public/Public/menu.html.twig line 1

Open in your IDE?
  1. {% macro renderAttributes(attributes) %}
  2. {% for attributeKey, attributeValue in attributes -%}
  3. {{ attributeKey }}="{{ attributeValue }}"
  4. {%- endfor %}
  5. {% endmacro %}
  6. {% macro render_menu(item) %}
  7. {% import _self as macros %}
  8. {% set itemUri = null %}
  9. {% if item.url is not empty %}
  10. {% set itemUri = item.url %}
  11. {% elseif item.path is not empty %}
  12. {% set itemParameters = item.parameterValue + ['_locale', item.locale] %}
  13. {% set itemUri = path(item.path, item.parameterValue) %}
  14. {% endif %}
  15. {% if item.items is not empty %}
  16. <li class="menu-item-with-children">
  17. <a class="dropdown-item">{{ item.title }}</a>
  18. <ul>
  19. {% for subitem in item.items %}
  20. {% set subItemUri = null %}
  21. {% if subitem.url is not empty %}
  22. {% set subItemUri = subitem.url %}
  23. {% elseif subitem.path is not empty %}
  24. {% set subItemParameters = subitem.parameterValue + ['_locale', item.locale] %}
  25. {% set subItemUri = path(subitem.path, subitem.parameterValue) %}
  26. {% endif %}
  27. {% if subItemUri is not null %}
  28. {% set attrs = subitem.attributes is iterable ? subitem.attributes : {} %}
  29. {% set desc = attrs['data-description']|default('') %}
  30. {% set subImg = subitem.attributes['data-image']|default(null) %}
  31. <li
  32. data-description="{{ desc|e('html_attr') }}"
  33. {% if subImg %}
  34. data-has-image="1"
  35. style="--menu-preview-image: url('{{ asset(subImg) }}');"
  36. {% endif %}>
  37. <a href="{{ subItemUri }}">{{ subitem.title }}</a>
  38. </li>
  39. {% endif %}
  40. {% endfor %}
  41. </ul>
  42. </li>
  43. {% elseif itemUri is not null %}
  44. <li>
  45. <a class="dropdown-item" href="{{ itemUri }}">{{ item.title }}</a>
  46. </li>
  47. {% endif %}
  48. {% endmacro %}
  49. {% if menu is not empty %}
  50. {% import _self as macros %}
  51. <ul {{ macros.renderAttributes(menu.attributes) }}>
  52. {% for item in menu.items %}
  53. {% set hasRight = item.right is empty or is_granted(item.right) == item.hasRight %}
  54. {% if hasRight %}
  55. {% set attributes = item.attributes %}
  56. {% if attributes.class is defined %}
  57. {% set class = attributes.class|split(' ')|merge(['nav-item']) %}
  58. {% else %}
  59. {% set class = ['nav-item'] %}
  60. {% endif %}
  61. {% if item.slug is not empty %}
  62. {% set class = class|merge(['link-'~item.slug]) %}
  63. {% endif %}
  64. {% if loop.first %}
  65. {% set class = class|merge(['first']) %}
  66. {% endif %}
  67. {% if loop.last %}
  68. {% set class = class|merge(['last']) %}
  69. {% endif %}
  70. {% set uri = '' %}
  71. {% if item.url is not empty %}
  72. {% set uri = item.url %}
  73. {% elseif item.path is not empty %}
  74. {% set parameters = item.parameterValue + ['_locale', item.locale] %}
  75. {% set uri = path(item.path, item.parameterValue) %}
  76. {% endif %}
  77. {% set activeRoute = app.request.attributes.get('_route') %}
  78. {% set activeQuery = app.request.query.all %}
  79. {% set isActive = item.path == activeRoute and item.parameterValue == activeQuery %}
  80. {% if uri is not null %}
  81. {% set attributes = attributes|merge({class:class|join(' ')}) %}
  82. <li {{ macros.renderAttributes(attributes) }}>
  83. {% if item.items is not empty %}
  84. <a class="nav-link dropdown-toggle accordion-header"
  85. data-toggle="dropdown"
  86. aria-haspopup="true"
  87. aria-expanded="false">{{ item.title }}</a>
  88. <ul class="dropdown-menu" aria-labelledby="dLabel">
  89. {% for subitem in item.items %}
  90. {{ macros.render_menu(subitem) }}
  91. {% endfor %}
  92. </ul>
  93. {% else %}
  94. <a class="nav-link {{ isActive ? 'active' : '' }}" href="{{ uri }}">{{ item.title }}</a>
  95. {% endif %}
  96. {% if attributes['data-image'] is defined %}
  97. <img src="{{ asset(attributes['data-image']) }}" alt="{{ item.title }}" />
  98. {% endif %}
  99. </li>
  100. {% endif %}
  101. {% endif %}
  102. {% endfor %}
  103. </ul>
  104. {% endif %}
  105. {% block javascripts %}
  106. {# {{ parent() }}#}
  107. {# <script type="application/javascript" src="{{ asset('assets/app/menu.js') }}"></script>#}
  108. {{ encore_entry_script_tags('app/dropdown_menu') }}
  109. {% endblock %}