Skip to content

Instantly share code, notes, and snippets.

@dan-gamble
Created April 17, 2019 12:52
Show Gist options
  • Save dan-gamble/e5961064d76bae448f5c721ee194ed52 to your computer and use it in GitHub Desktop.
Save dan-gamble/e5961064d76bae448f5c721ee194ed52 to your computer and use it in GitHub Desktop.
{%- assign should_have_breadcrumb = false -%}
{%- assign breadcrumbs_linklist = linklists.collection-tree -%}
{%- assign breadcrumbs = '' -%}
{%- assign collection_handle = collection.handle -%}
{%- assign breadcrumb_link = nil -%}
{%- assign child_breadcrumb_link = nil -%}
{%- assign grandchild_breadcrumb_link = nil -%}
{%- for link in breadcrumbs_linklist.links -%}
{%- if child_breadcrumb_link != nil -%}
{% break %}
{%- endif -%}
{%- if link.type != 'collection_link' -%}
{% continue %}
{%- endif -%}
{%- assign link_collection_handle = link.object.handle -%}
{%- if link_collection_handle == collection_handle -%}
{%- assign should_have_breadcrumb = true -%}
{%- assign breadcrumb_link = link -%}
{%- break -%}
{%- endif -%}
{%- if link.links.size > 0 -%}
{%- for child_link in link.links -%}
{%- if grandchild_breadcrumb_link != nil -%}
{% break %}
{%- endif -%}
{%- if link.type != 'collection_link' -%}
{% continue %}
{%- endif -%}
{%- assign link_collection_handle = child_link.object.handle -%}
{%- if link_collection_handle == collection_handle -%}
{%- assign should_have_breadcrumb = true -%}
{%- assign breadcrumb_link = link -%}
{%- assign child_breadcrumb_link = child_link -%}
{%- break -%}
{%- endif -%}
{%- if child_link.links.size > 0 -%}
{%- for grandchild_link in child_link.links -%}
{%- if link.type != 'collection_link' -%}
{% continue %}
{%- endif -%}
{%- assign link_collection_handle = grandchild_link.object.handle -%}
{%- if link_collection_handle == collection_handle -%}
{%- assign should_have_breadcrumb = true -%}
{%- assign breadcrumb_link = link -%}
{%- assign child_breadcrumb_link = child_link -%}
{%- assign grandchild_breadcrumb_link = grandchild_link -%}
{%- break -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- if should_have_breadcrumb -%}
{%- if breadcrumb_link -%}
{%- assign breadcrumbs = '|' | append: breadcrumb_link.title | append: ',' | append: breadcrumb_link.url -%}
{%- endif -%}
{%- if child_breadcrumb_link -%}
{%- assign breadcrumbs = breadcrumbs | append: '|' | append: child_breadcrumb_link.title | append: ',' | append: child_breadcrumb_link.url -%}
{%- endif -%}
{%- if grandchild_breadcrumb_link -%}
{%- assign breadcrumbs = breadcrumbs | append: '|' | append: grandchild_breadcrumb_link.title | append: ',' | append: grandchild_breadcrumb_link.url -%}
{%- endif -%}
{%- assign breadcrumbs = breadcrumbs | remove_first: '|' | split: '|' -%}
{%- endif -%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment