Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {% macro list(items, class) %}
- <ul class="{{class}}">
- {# Iterating over each direct items #}
- {% for item in items %}
- <li>
- <a href="">{{item.name}}</a>
- {# If an item has children #}
- {% if item.children %}
- {# Re-import the macro #}
- {% import _self as recursive %}
- {# And use it to iterate over item's children #}
- {{ recursive.list(item.children) }}
- {% endif %}
- </li>
- {% endfor %}
- </ul>
- {% endmacro %}
- {# Nav Being the variable passed to the template #}
- {% if nav %}
- {# importing the macro created earlier #}
- {% import _self as tree %}
- {# using macro {nameOfImport}.{nameOfMethod}(variable) #}
- {{ tree.list(nav.children) }}
- {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement