Skip to content

Instantly share code, notes, and snippets.

@zakhardage
Created September 1, 2013 05:16
Show Gist options
  • Save zakhardage/6402487 to your computer and use it in GitHub Desktop.
Save zakhardage/6402487 to your computer and use it in GitHub Desktop.
This is an example of displaying breadcrumbs for products within a sub-collection in Shopify.
{% for link in linklists.sidebar.links %}
{% assign cur_parent = link.title | handleize %}
{% assign cur_parent_url = link.url %}
{% if linklists.[cur_parent].links.size > 0 %}
{% for link in linklists.[cur_parent].links %}
{% if link.title == collection.title %}
{% assign parent = cur_parent %}
{% assign parent_url = cur_parent_url %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
<div class="breadcrumbs">
<a href="/">home</a> //
{% if parent.size > 0 %}<a href="{{ parent_url }}">{{ parent }}</a> //{% endif %}
<a href="{{ collection.url }}">{{ collection.title }}</a>
</div> <!-- end #breadcrumbs -->
@archampion
Copy link

Hi, I am trying to create 2 levels down. How to I get grandparent url when I'm at second level?

Here's my code,

{% for link in linklists.main-menu.links %}
{% assign cur_parent = link.handle %}
{% assign cur_parent_title = link.title %}
{% assign cur_parent_url = link.url %}

{% if linklists[cur_parent].links.size > 0 %}
{% for link in linklists.[cur_parent].links %}
{% assign cur_parent_2 = link.handle %}
{% assign cur_parent_title_2 = link.title %}
{% assign cur_parent_url_2 = link.url %}

  {% if link.title == collection.title %}
    {% assign parent = cur_parent_title %}
    {% assign parent_url = cur_parent_url %}

  {% endif %}

    {% if linklists[cur_parent_2].links.size > 0 %}
      {% for link in linklists.[cur_parent_2].links %}
        {% if link.title == collection.title %}
          {% assign parent_2 = cur_parent_title_2 %}
          {% assign parent_url_2 = cur_parent_url_2 %}
        {% endif %}

      {% endfor %}
    {% endif %}
{% endfor %}

{% endif %}
{% endfor %}

{% if parent.size > 0 %} {{ parent }} {{ collection.title }} {% else %} {{ collection.title }}{% endif %}

{% if parent_2.size > 0 %} {{ parent_2 }} {{ collection.title }}{% endif %}

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