tab_menu_template.html.twig 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 is defined %} {# KnpMenu 2.0#}
  17. {%- if matcher.isCurrent(item) %}
  18. {%- set classes = classes|merge([options.currentClass]) %}
  19. {%- elseif matcher.isAncestor(item, options.depth) %}
  20. {%- set classes = classes|merge([options.ancestorClass]) %}
  21. {%- endif %}
  22. {%- else %} {# KnpMenu 1.X #}
  23. {%- if item.current %}
  24. {%- set classes = classes|merge([options.currentClass]) %}
  25. {%- elseif item.currentAncestor %}
  26. {%- set classes = classes|merge([options.ancestorClass]) %}
  27. {%- endif %}
  28. {%- endif %}
  29. {%- if item.actsLikeFirst %}
  30. {%- set classes = classes|merge([options.firstClass]) %}
  31. {%- endif %}
  32. {%- if item.actsLikeLast %}
  33. {%- set classes = classes|merge([options.lastClass]) %}
  34. {%- endif %}
  35. {# building the class of the children #}
  36. {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %}
  37. {%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %}
  38. {# adding classes for dropdown #}
  39. {%- if is_dropdown %}
  40. {%- set classes = classes|merge(['dropdown']) %}
  41. {%- set childrenClasses = childrenClasses|merge(['dropdown-menu']) %}
  42. {%- endif %}
  43. {# putting classes together #}
  44. {%- if classes is not empty %}
  45. {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  46. {%- endif %}
  47. {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %}
  48. {# displaying the item #}
  49. <li{{ macros.attributes(attributes) }}>
  50. {%- if is_dropdown %}
  51. {{ block('dropdownElement') }}
  52. {%- elseif item.uri is not empty and (not item.current or options.currentAsLink) %}
  53. {{ block('linkElement') }}
  54. {%- else %}
  55. {{ block('spanElement') }}
  56. {%- endif %}
  57. {# render the list of children#}
  58. {{ block('list') }}
  59. </li>
  60. {%- if divider_append %}
  61. {{ block('dividerElement') }}
  62. {%- endif %}
  63. {% endif %}
  64. {% endblock %}
  65. {% block dividerElement %}
  66. {% if item.level == 1 %}
  67. <li class="divider-vertical"></li>
  68. {% else %}
  69. <li class="divider"></li>
  70. {% endif %}
  71. {% endblock %}
  72. {% block linkElement %}
  73. <a href="{{ item.uri }}"{{ macros.attributes(item.linkAttributes) }}>
  74. {% if item.attribute('icon') is not empty %}
  75. <i class="{{ item.attribute('icon') }}"></i>
  76. {% endif %}
  77. {{ block('label') }}
  78. </a>
  79. {% endblock %}
  80. {% block spanElement %}
  81. <span {{ macros.attributes(item.labelAttributes) }}>
  82. {% if item.attribute('icon') is not empty %}
  83. <i class="{{ item.attribute('icon') }}"></i>
  84. {% endif %}
  85. {{ block('label') }}
  86. </span>
  87. {% endblock %}
  88. {% block dropdownElement %}
  89. {%- set classes = item.linkAttribute('class') is not empty ? [item.linkAttribute('class')] : [] %}
  90. {%- set classes = classes|merge(['dropdown-toggle']) %}
  91. {%- set attributes = item.linkAttributes %}
  92. {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  93. {%- set attributes = attributes|merge({'data-toggle': 'dropdown'}) %}
  94. <a href="#"{{ macros.attributes(attributes) }}>
  95. {% if item.attribute('icon') is not empty %}
  96. <i class="{{ item.attribute('icon') }}"></i>
  97. {% endif %}
  98. {{ block('label') }}
  99. <b class="caret"></b>
  100. </a>
  101. {% endblock %}
  102. {% block label %}{{ item.label|trans }}{% endblock %}