Skip to content

Instantly share code, notes, and snippets.

@ChrisSavoie
Created August 25, 2017 14:08
Show Gist options
  • Save ChrisSavoie/306916c01a33ac2491b055fa0c81fdec to your computer and use it in GitHub Desktop.
Save ChrisSavoie/306916c01a33ac2491b055fa0c81fdec to your computer and use it in GitHub Desktop.
'Recursive Snippet Include' to make nested navigation. o use, simply `{% include 'bms-megamenu' [with linklist_object] %}` (where `linklist_obj` would be replaced with some linklist on your store to serve as the top level controller, defaulting to a linklist named 'megamenu-top' if none is provided) Linklist structure: If the element in the link…
{% comment %}
Created by: BMS - DB
Megamenu: Output nested lists to be styled as a menu
{% endcomment %}
{% assign list = bms-megamenu | default: linklists['megamenu-top'] %}
{% assign layer_depth = depth | default: 0 %}
{% assign next_layer_depth = layer_depth | plus: 1 %}
<ul data-layer="{{ layer_depth }}">
{% for link in list.links %}
<li>
{% assign sublist = linklists[link.object.handle] %}
{% if sublist != blank and layer_depth < 100 %}
<a href="javascript:void(0)" class="menu-control" data-menu-for="{{ link.object.handle }}">{{ link.title }}</a>
{% include 'bms-megamenu' with sublist, depth: next_layer_depth %}
{% else %}
{% if link.active %}
<strong class="current-page">{{ link.title }}</strong>
{% else %}
<a href="{{ link.url }}">{{ link.title }}</a>
{% endif %}
{% endif %}
{% endfor %}
</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment