Skip to content

Instantly share code, notes, and snippets.

@dav11d
Created April 18, 2018 13:47
Show Gist options
  • Save dav11d/69bfff5bb998856fdc6aef16f1d530ab to your computer and use it in GitHub Desktop.
Save dav11d/69bfff5bb998856fdc6aef16f1d530ab to your computer and use it in GitHub Desktop.
Shopify Sidebar Tag Filter
<aside id="collection-filters">
<h2>Narrow Results</h2>
{% comment %}Exceptions{% endcomment %}
{% if collection.handle contains 'x' %}{% assign handle = 'y' %}
{% else %}{% assign handle = collection.handle %}{% endif %}
{% for i in (1..5) %}
{% capture include_filter %}{{ handle }}_filter_no_{{ i }}_enable{% endcapture %}
<!-- {{ include_filter }} -->
{% if settings[include_filter] %}
{% capture include_filter %}include_{{ handle }}_filter_no_{{ i }}{% endcapture %}
{% capture filter_label %}{{ handle }}_filter_no_{{ i }}_label{% endcapture %}
{% capture filter_linklist %}{{ handle }}_filter_no_{{ i }}_linklist{% endcapture %}
{% if settings[filter_label] != '' %}
<h3 class="narrow_title">{{ settings[filter_label] }}</h3>
{% endif %}
<ul>
{% include 'filter-by-tag' with settings[filter_linklist] %}
</ul>
{% endif %}
{% endfor %}
<a href="{{ collection.url }}"><i>Remove all filters</i></a>
</aside>
{% assign all_filter_tags = '' %}
{% for link in linklists[filter-by-tag].links %}
{% if collection.all_tags contains link.title %}
{% capture all_filter_tags %}{{ all_filter_tags }},{{ link.title }}{% endcapture %}
{% endif %}
{% endfor %}
{% assign new_tags = '' %}
{% for tag in current_tags %}
{% capture new_tags %}{{ new_tags }}+{{ tag | handle }}{% endcapture %}
{% endfor %}
{% capture new_tags %}{{ new_tags | remove_first: '+' }}{% endcapture %}
{% for link in linklists[filter-by-tag].links %}
{% if collection.tags contains link.title %}
{% if current_tags contains link.title %}
<li>{{ link.title | link_to_remove_tag: link.title }}</li>
{% else %}
{% if collection.url != '' %}
{% capture url %}{{ collection.url }}/{% if new_tags != '' %}{{ new_tags }}+{% endif %}{{ link.title | handle }}{% endcapture %}
{% else %}
{% capture url %}/collections/all/{% if new_tags != '' %}{{ new_tags }}+{% endif %}{{ link.title | handle }}{% endcapture %}
{% endif %}
<li>{{ link.title | link_to: url }}</li>
{% endif %}
{% endif %}
{% endfor %}
{% if collection.url != '' %}
{% capture url %}{{ collection.url }}{% if new_tags != '' %}/{{ new_tags }}{% endif %}{% endcapture %}
{% else %}
{% capture url %}/collections/all{% if new_tags != '' %}/{{ new_tags }}{% endif %}{% endcapture %}
{% endif %}
{
"name": "Collection Filters",
"settings": [
{
"type": "paragraph",
"content": "Seasonal Collection Filters"
},
{
"type": "checkbox",
"id": "seasonal_filter_no_1_enable",
"label": "Use filter 1?"
},
{
"type": "text",
"id": "seasonal_filter_no_1_label",
"label": "Filter 1 Label"
},
{
"type": "link_list",
"id": "seasonal_filter_no_1_linklist",
"label": "Filter 1 Linklist"
},
{
"type": "checkbox",
"id": "seasonal_filter_no_2_enable",
"label": "Use filter 2?"
},
{
"type": "text",
"id": "seasonal_filter_no_2_label",
"label": "Filter 2 Label"
},
{
"type": "link_list",
"id": "seasonal_filter_no_2_linklist",
"label": "Filter 2 Linklist"
},
{
"type": "checkbox",
"id": "seasonal_filter_no_3_enable",
"label": "Use filter 3?"
},
{
"type": "text",
"id": "seasonal_filter_no_3_label",
"label": "Filter 3 Label"
},
{
"type": "link_list",
"id": "seasonal_filter_no_3_linklist",
"label": "Filter 3 Linklist"
},
{
"type": "checkbox",
"id": "seasonal_filter_no_4_enable",
"label": "Use filter 4?"
},
{
"type": "text",
"id": "seasonal_filter_no_4_label",
"label": "Filter 4 Label"
},
{
"type": "link_list",
"id": "seasonal_filter_no_4_linklist",
"label": "Filter 4 Linklist"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment