Last active
August 29, 2015 14:22
-
-
Save mmikkel/61a8c8b3db728cdfdbbd to your computer and use it in GitHub Desktop.
Output sub nav from related nav item, from the top level entry
This file contains hidden or 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
{# 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