Last active
January 16, 2016 08:12
-
-
Save johandouma/73b5da17334773138d60 to your computer and use it in GitHub Desktop.
Craft CMS + Foundation Top Bar Twig Macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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