Lego2012
9/26/2016 - 9:22 PM

Nested Page Navigation without Plugins

Nested Page Navigation without Plugins

{% capture html %}
<ul>
  {% if include.context == "/" %}
    <li class="{% if page.url == "/" %}active{% endif %}">
        <a href="{{ site.baseurl }}/">{{ site.title }}</a>
    </li>
  {% endif %}
  
  {% assign entries = site.pages | sort: "path" %}
  
  {% for entry in entries %}
    {% capture slug    %}{{ entry.url | split: "/"   | last                       }}{% endcapture %}
    {% capture current %}{{ entry.url | remove: slug | remove: "//" | append: "/" }}{% endcapture %}
    {% if current == include.context %}
      <li class="{% if page.url contains entry.url %}active{% endif %}">
          <a href="{{ site.baseurl }}{{ entry.url }}">{{ entry.title }}</a>
          {% include navigation.html context=entry.url %}
      </li>
    {% endif %}
  {% endfor %}
</ul>
{% endcapture %}
{{ html | strip_newlines | replace:'    ','' | replace:'    ','' | replace:'  ',' ' }}