Skip to content

Instantly share code, notes, and snippets.

@iainurquhart
Last active August 29, 2015 14:00
Show Gist options
  • Save iainurquhart/11363859 to your computer and use it in GitHub Desktop.
Save iainurquhart/11363859 to your computer and use it in GitHub Desktop.
Auto expanding navigation (Only siblings of parents displayed)
{% set topEntry = craft.entries.depth(1).slug('about-us').first() %}
{% set parents = entry.getAncestors() %}
<ul>
{% nav item in topEntry.getDescendants() %}
{% set showChildren = false %}
{% for parentItems in parents %}
{% if parentItems.id == item.id or entry.id == item.id %}
{% set showChildren = true %}
{% endif %}
{% endfor %}
<li class="level_{{ item.depth }}">{{ item.link }}
{# fine #}
{% if showChildren %}
x
{% endif %}
{# shits itself here #}
{% if showChildren %}
{% ifchildren %}
<ul>{% children %}</ul>
{% endifchildren %}
{% endif %}
</li>
{% endnav %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment