Skip to content

Instantly share code, notes, and snippets.

@MisterPoppet
Last active August 29, 2015 14:21
Show Gist options
  • Save MisterPoppet/b5dce9de76bbd868ee6a to your computer and use it in GitHub Desktop.
Save MisterPoppet/b5dce9de76bbd868ee6a to your computer and use it in GitHub Desktop.
Recursive Macro
{% macro menu(items, class, home) %}
{% import _self as parts %}
<div class="lucky {{ class|default('main') }} menu">
{% if home|default(true) %}
<a href="{{ siteUrl }}">Home</a>
{% endif %}
{{ parts.menuItems(items) }}
</div>
{% endmacro %}
{% macro menuItems(items) %}
{% import _self as parts %}
{% for item in items %}
{% if item.hasDescendants() %}
<div class="item">
<a href="{{ item.url }}">{{ item.title }}</a>
<div class="submenu">
{{ parts.menuItems(item.getChildren()) }}
</div>
</div>
{% else %}
<a class="item" href="{{ item.url }}">{{ item.title }}</a>
{% endif %}
{% endfor %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment