Skip to content

Instantly share code, notes, and snippets.

@johandouma
Last active January 16, 2016 08:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johandouma/73b5da17334773138d60 to your computer and use it in GitHub Desktop.
Save johandouma/73b5da17334773138d60 to your computer and use it in GitHub Desktop.
Craft CMS + Foundation Top Bar Twig Macro
{% macro menu(entries, active, level) %}
{% if entries|length %}
{% set level = level|default(1) %}
<ul class="level-{{ level }} {{ level > 1 ? "dropdown sub" : "left top" }}">
{% for n in entries %}
<li class="{{ loop.first ? "first" : "" }} {{ loop.last ? "last" : "" }}
{%- if n.children|length %}has-dropdown{% endif %}
{%- if active is defined and (active.descendantOf(n) or active.id == n.id) %} active{% endif %}">
<a href="{{ n.url }}">
{{ n }}
</a>
{% if n.children|length %}
{{ _self.menu(n.children, active, level+1) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
{% macro simple_menu(entries, active) %}
{% if entries|length %}
<ul class="side-nav">
{% for n in entries %}
<li class="{{ loop.first ? "first" : "" }} {{ loop.last ? "last" : "" }}
{%- if active is defined and active and (active.descendantOf(n) or active.id == n.id) %} active{% endif %}">
<a href="{{ n.url }}">
{{ n }}
</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment