You are here

bef-nested-elements.html.twig in Better Exposed Filters 8.3

{#
  Themes hierarchical taxonomy terms as nested <ul> elements.

  This template is intended to be called from within another template to provide
  the "scaffolding" of nested lists while the calling template provides the
  actual filter element via the 'item' variable.

  Available variables:
    - current_nesting_level: the nesting level of the most recently printe item.
    - new_nesting_level: the nesting level of the item to print.
    - item: The item to print.
    - loop: The loop variable from the iterator that calls this template.
      Requires the loop.first and loop.last elements.
#}
{% spaceless %}
  {% set delta = (current_nesting_level - new_nesting_level) | abs %}
  {% if loop.first %}
    <ul>
  {% else %}
    {% if delta %}
      {% for i in 1..delta %}
        {% if new_nesting_level > current_nesting_level  %}
          <ul>
        {% else %}
          </li></ul>
        {% endif %}
      {% endfor %}
    {% endif %}
  {% endif %}

  <li>{{ item }}

  {% if loop.last %}
    {# Close any remaining <li> tags #}
    {% for i in new_nesting_level..0 %}
      </li>
    {% endfor %}
    </ul>
  {% endif %}
{% endspaceless %}

File

templates/bef-nested-elements.html.twig
View source
  1. {#
  2. Themes hierarchical taxonomy terms as nested <ul> elements.
  3. This template is intended to be called from within another template to provide
  4. the "scaffolding" of nested lists while the calling template provides the
  5. actual filter element via the 'item' variable.
  6. Available variables:
  7. - current_nesting_level: the nesting level of the most recently printe item.
  8. - new_nesting_level: the nesting level of the item to print.
  9. - item: The item to print.
  10. - loop: The loop variable from the iterator that calls this template.
  11. Requires the loop.first and loop.last elements.
  12. #}
  13. {% spaceless %}
  14. {% set delta = (current_nesting_level - new_nesting_level) | abs %}
  15. {% if loop.first %}
  16. <ul>
  17. {% else %}
  18. {% if delta %}
  19. {% for i in 1..delta %}
  20. {% if new_nesting_level > current_nesting_level %}
  21. <ul>
  22. {% else %}
  23. </li></ul>
  24. {% endif %}
  25. {% endfor %}
  26. {% endif %}
  27. {% endif %}
  28. <li>{{ item }}
  29. {% if loop.last %}
  30. {# Close any remaining <li> tags #}
  31. {% for i in new_nesting_level..0 %}
  32. </li>
  33. {% endfor %}
  34. </ul>
  35. {% endif %}
  36. {% endspaceless %}