Skip to content

Instantly share code, notes, and snippets.

@kyleaparker
Created February 6, 2014 20:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyleaparker/8851659 to your computer and use it in GitHub Desktop.
Save kyleaparker/8851659 to your computer and use it in GitHub Desktop.
Shopify: Map all collection tags (avoid 50 product limit)
{% assign collection_tags = collection | map: 'tags' %}
{% for tag in collection_tags %}
<a href="/collections/{% if collection.handle != blank %}{{ collection.handle }}{% else %}all{% endif %}/{{ tag | handleize }}" title="{{ tag | escape }}">{{ tag }}</a>
{% endfor %}
@darryn
Copy link

darryn commented Apr 9, 2014

@kyleaparker can you use the map filter to create an array of all the product titles in a collection? E.g. something like:

{% assign all_products = collections.all | map: 'products' %}
{% for product in all_products %}
{{ product.title }}
{% endfor %}

Also, I noticed that the map filter seems to output a single string of values. If I add a forloop index to your tags/map snippet it only gives me one iteration.

{% assign collection_tags = collection | map: 'tags' %}
{% for tag in collection_tags %}
    {{ tag }} - {{ forloop.index }}
{% endfor %}

http://monosnap.com/image/t6mPYjgP8M7Y4hyADBH3sWQl7JbLkZ

Is this right? What be's going ons yo?

@kyleaparker
Copy link
Author

@darryn sorry just saw this!

Yup you can create an array of product titles. You would use something like:

{% assign all_products = collections.all.products | map: 'title' %}
{% for title in all_products %}
{{ title }}
{% endfor %}

I looks like it doesn't work with tags, possibly because collection.tags is already an array? Like this:

{% for tag in collection.tags %}
{{ forloop.index }}
{% endfor %}

However, your example would work like this:

{% assign collection_titles = collections.all.products | map: 'title' %}

{% for title in collection_titles %}
{{ forloop.index }} {{ title }}
{% endfor %}

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