tab_menu_template.html.twig 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. {% extends 'knp_menu.html.twig' %}
  2. {% block item %}
  3. {% import "knp_menu.html.twig" as macros %}
  4. {% if item.displayed %}
  5. {%- set attributes = item.attributes %}
  6. {%- set is_dropdown = attributes.dropdown|default(false) %}
  7. {%- set divider_prepend = attributes.divider_prepend|default(false) %}
  8. {%- set divider_append = attributes.divider_append|default(false) %}
  9. {# unset bootstrap specific attributes #}
  10. {%- set attributes = attributes|merge({'dropdown': null, 'divider_prepend': null, 'divider_append': null }) %}
  11. {%- if divider_prepend %}
  12. {{ block('dividerElement') }}
  13. {%- endif %}
  14. {# building the class of the item #}
  15. {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
  16. {%- if matcher.isCurrent(item) %}
  17. {%- set classes = classes|merge([options.currentClass]) %}
  18. {%- elseif matcher.isAncestor(item, options.depth) %}
  19. {%- set classes = classes|merge([options.ancestorClass]) %}
  20. {%- endif %}
  21. {%- if item.actsLikeFirst %}
  22. {%- set classes = classes|merge([options.firstClass]) %}
  23. {%- endif %}
  24. {%- if item.actsLikeLast %}
  25. {%- set classes = classes|merge([options.lastClass]) %}
  26. {%- endif %}
  27. {# building the class of the children #}
  28. {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %}
  29. {%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %}
  30. {# adding classes for dropdown #}
  31. {%- if is_dropdown %}
  32. {%- set classes = classes|merge(['dropdown']) %}
  33. {%- set childrenClasses = childrenClasses|merge(['dropdown-menu']) %}
  34. {%- endif %}
  35. {# putting classes together #}
  36. {%- if classes is not empty %}
  37. {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  38. {%- endif %}
  39. {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %}
  40. {# displaying the item #}
  41. <li{{ macros.attributes(attributes) }}>
  42. {%- if is_dropdown %}
  43. {{ block('dropdownElement') }}
  44. {%- elseif item.uri is not empty and (not item.current or options.currentAsLink) %}
  45. {{ block('linkElement') }}
  46. {%- else %}
  47. {{ block('spanElement') }}
  48. {%- endif %}
  49. {# render the list of children#}
  50. {{ block('list') }}
  51. </li>
  52. {%- if divider_append %}
  53. {{ block('dividerElement') }}
  54. {%- endif %}
  55. {% endif %}
  56. {% endblock %}
  57. {% block dividerElement %}
  58. {% if item.level == 1 %}
  59. <li class="divider-vertical"></li>
  60. {% else %}
  61. <li class="divider"></li>
  62. {% endif %}
  63. {% endblock %}
  64. {% block linkElement %}
  65. <a href="{{ item.uri }}"{{ macros.attributes(item.linkAttributes) }}>
  66. {% if item.attribute('icon') is not empty %}
  67. <i class="{{ item.attribute('icon') }}"></i>
  68. {% endif %}
  69. {{ block('label') }}
  70. </a>
  71. {% endblock %}
  72. {% block spanElement %}
  73. <span>{{ macros.attributes(item.labelAttributes) }}>
  74. {% if item.attribute('icon') is not empty %}
  75. <i class="{{ item.attribute('icon') }}"></i>
  76. {% endif %}
  77. {{ block('label') }}
  78. </span>
  79. {% endblock %}
  80. {% block dropdownElement %}
  81. {%- set classes = item.linkAttribute('class') is not empty ? [item.linkAttribute('class')] : [] %}
  82. {%- set classes = classes|merge(['dropdown-toggle']) %}
  83. {%- set attributes = item.linkAttributes %}
  84. {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  85. {%- set attributes = attributes|merge({'data-toggle': 'dropdown'}) %}
  86. <a href="#"{{ macros.attributes(attributes) }}>
  87. {% if item.attribute('icon') is not empty %}
  88. <i class="{{ item.attribute('icon') }}"></i>
  89. {% endif %}
  90. {{ block('label') }}
  91. <b class="caret"></b>
  92. </a>
  93. {% endblock %}
  94. {% block label %}{{ item.label|trans }}{% endblock %}