Skip to content

Instantly share code, notes, and snippets.

@silentworks
Last active December 24, 2016 19:01
Show Gist options
  • Save silentworks/e5bd115f743881c6385e to your computer and use it in GitHub Desktop.
Save silentworks/e5bd115f743881c6385e to your computer and use it in GitHub Desktop.
Getting menu to stay active for sub sections
{% macro display_menu_item(item, loop) %}
{% from _self import display_menu_item %}
{% set menuPath = item.link[1:] != '' ? '/' ~ item.link[1:] ~ '/' : 'home' %}
<li class="main-nav-item index-{{ loop.index }}{% if loop.first %} first{% endif %}{% if loop.last %} last{% endif %}{% if item.submenu is defined %} has-dropdown{% endif %}{% if item|current or menuPath in paths.current %} active{% endif %}">
<a href="{{ item.link }}" {% if item.title is defined %}title='{{ item.title|escape }}'{% endif %}
class='{% if item.class is defined %}{{item.class}}{% endif %}'>
{{item.label}}
</a>
{% if item.submenu is defined %}
<ul class="dropdown">
{% for submenu in item.submenu %}
{{ display_menu_item(submenu, loop) }}
{% endfor %}
</ul>
{% endif %}
</li>
{% endmacro %}
{% from _self import display_menu_item %}
{% for item in menu %}
{% if item.label is defined %}
{{ display_menu_item(item, loop) }}
{% endif %}
{% endfor %}
@silentworks
Copy link
Author

Line 3 and 4 is where the magic happen

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