Skip to content

Instantly share code, notes, and snippets.

@iainurquhart
Created April 28, 2014 21:48
Show Gist options
  • Save iainurquhart/11385028 to your computer and use it in GitHub Desktop.
Save iainurquhart/11385028 to your computer and use it in GitHub Desktop.
active and active_parent classes to navigation
{% set topEntry = craft.entries.depth(1).slug('about-us').first() %}
{% set parents = entry.getAncestors() %}
<ul>
{% nav item in topEntry.getDescendants() %}
{% set isParent = false %}
{% for parentItems in parents %}
{% if parentItems.id == item.id %}
{% set isParent = true %}
{% endif %}
{% endfor %}
<li class="level_{{ item.depth }}{% if isParent %} active_parent{% endif %}{% if entry.id == item.id %} active{% endif %}">{{ item.link }}
{% ifchildren %}
<ul>{% children %}</ul>
{% endifchildren %}
</li>
{% endnav %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment