Advertisement
Guest User

Untitled

a guest
May 24th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. {% macro list(items, class) %}
  2. <ul class="{{class}}">
  3.  
  4. {# Iterating over each direct items #}
  5. {% for item in items %}
  6. <li>
  7. <a href="">{{item.name}}</a>
  8.  
  9. {# If an item has children #}
  10. {% if item.children %}
  11. {# Re-import the macro #}
  12. {% import _self as recursive %}
  13. {# And use it to iterate over item's children #}
  14. {{ recursive.list(item.children) }}
  15. {% endif %}
  16. </li>
  17. {% endfor %}
  18. </ul>
  19. {% endmacro %}
  20.  
  21.  
  22. {# Nav Being the variable passed to the template #}
  23. {% if nav %}
  24. {# importing the macro created earlier #}
  25. {% import _self as tree %}
  26.  
  27. {# using macro {nameOfImport}.{nameOfMethod}(variable) #}
  28. {{ tree.list(nav.children) }}
  29. {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement