Skip to content

Instantly share code, notes, and snippets.

@mmikkel
Last active August 29, 2015 14:22
Show Gist options
  • Save mmikkel/61a8c8b3db728cdfdbbd to your computer and use it in GitHub Desktop.
Save mmikkel/61a8c8b3db728cdfdbbd to your computer and use it in GitHub Desktop.
Output sub nav from related nav item, from the top level entry
{# Get the related nav item for the current entry #}
{% set navItem = craft.entries.section('navigation').relatedTo(entry).first() %}
{% if navItem %}
{# Get the top level page for the nav item #}
{% set topPage = navItem.getAncestors().level(1).first()|default(navItem) %}
{# Build a "pages" array w/ the top page and its descendents (child entries) #}
{% set pages = craft.entries.id([topPage.id]|merge(topPage.getDescendants().ids()|default([]))) %}
<nav>
<ul>
{% nav page in pages %}
<li>
<a href="{{ page.singleEntrySelector.first().url | default }}">{{ page.title }}</a>
{% ifchildren %}
<ul>
{% children %}
</ul>
{% endifchildren %}
</li>
{% endnav %}
</ul>
</nav>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment