Skip to content

Instantly share code, notes, and snippets.

@fredkelly
Last active April 19, 2018 13:38
Show Gist options
  • Save fredkelly/1e73f8ebf642a2f370ce5e069a044d30 to your computer and use it in GitHub Desktop.
Save fredkelly/1e73f8ebf642a2f370ce5e069a044d30 to your computer and use it in GitHub Desktop.
Generating a nested navigation in Jekyll with Liquid
{% assign pages = site.html_pages | where: 'visible', true | where_exp: 'page', 'page.url contains include.context' | group_by: 'dir' %}
<ul>
{% for group in pages %}
{% if group.size > 1 and group.name != include.context %}
<li class="{% if page.url contains group.name %}active{% endif %}">
<span>{{ group.name | replace: '/', '' | capitalize }}</span>
{% include navigation.html context=group.name %}
</li>
{% else %}
{% for item in group.items %}
<li>
<a href="{{ item.url }}">{{ item.title }}</a>
</li>
{% endfor %}
{% endif %}
{% endfor %}
</ul>
@cbaba20
Copy link

cbaba20 commented Jun 11, 2017

hi fred,
I am following your code to get a dropdown in my project page ,but it is not working. can you help on understanding these lines ?
{% if group.size > 1 and group.name != include.context %}<li class="{% if page.url contains group.name %}active{% endif %}"><span>{{ group.name | replace: '/', '' | capitalize }}</span>{% include navigation.html context=group.name %}</li>

@sidpagariya
Copy link

Hello, Fred!
Same here, could you please help us with a quick overview of your code?
Thanks!

@artyomb
Copy link

artyomb commented Apr 19, 2018

It works without "group.size > 1 and"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment