Skip to content

Instantly share code, notes, and snippets.

@sskylar
Last active July 10, 2018 21:17
Show Gist options
  • Select an option

  • Save sskylar/2f5875e733d7959b630f to your computer and use it in GitHub Desktop.

Select an option

Save sskylar/2f5875e733d7959b630f to your computer and use it in GitHub Desktop.
Sidebar nav for pages/subpages in Siteleaf v1
{% comment %} 1. Extract 'section' from '/section/page/subpage' {% endcomment %}
{% assign section = url | remove_first:'/' | split:'/' | first %}
{% comment %} 2. Loop through pages in this section {% endcomment %}
<ul>
{% for page in site.pages[section].pages %}
<li>
<a href="{{page.url}}"{% if page.url == curent.url %}class="selected"{% endif %}>{{page.title}}</a>
{% comment %} 3. Expand subnav for current page or any subpage {% endcomment %}
{% if current.url contains page.url and page.pages.size > 0 %}
<ul>
{% for subpage in page.pages %}
<li><a href="{{subpage.url}}"{% if page.url == curent.url %} class="selected"{% endif %}>{{subpage.title}}</a></li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment