Skip to content

Instantly share code, notes, and snippets.

@ihorduchenko
Last active September 5, 2017 06:04
Show Gist options
  • Save ihorduchenko/899dc81471f1b10f1f1c5ca69bb01547 to your computer and use it in GitHub Desktop.
Save ihorduchenko/899dc81471f1b10f1f1c5ca69bb01547 to your computer and use it in GitHub Desktop.
Output list of products types for certain collection
{% if collection %}
<ul>
{% assign typeList = '' %}
<!-- if we have a collection, then we don't need to access it through collections... -->
{% for product in collection.all_products %}
{% capture type %}{{product.type}}{% endcapture %}
<!-- using 'unless' instead of 'if () do nothing else do something' -->
{% unless typeList contains type %}
<li>{{ product.type | link_to_type }}</li>
{% capture temp %}{{typeList}}{{product.type}}{% endcapture %}
{% assign typeList = temp %}
{% endunless %}
{% endfor %}
</ul>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment