collection

You can use the collection variable in the following templates: 404.liquid, article.liquid, blog.liquid, collection.liquid, page.liquid, product.liquid and theme.liquid.

The liquid variable collection has the following attributes:

collection.all_products
{% for product in collection.all_products %}
  {{ product.id }}
{% endfor %}

Returns all of the products associated with a collection. Default limit is 50, but you can use pagination to retrieve less products.

collection.all_products_count
{{ collection.all_products_count }} {{ collection.all_products_count | pluralize: 'Item', 'Items' }} total

Returns a count of all of the products in a collection.

collection.all_tags
{% if collection.all_tags.size > 0 %}
  {% for tag in collection.all_tags %}
  {% if current_tags contains tag %}
  <li class="active">
    {{ tag | link_to_remove_tag: tag }}
  </li>
  {% else %}
  <li>
    {{ tag | link_to_tag: tag }}
  </li>
  {% endif %}
  {% endfor %}  
{% endif %}

Returns all of the tags associated with the collection.

collection.all_types
{% for product_type in collection.all_types %}
  {{ product_type | link_to_type }}
{% endfor %}

Returns a list of all of the unique product types in a collection.

collection.all_vendors
{% for product_vendor in collection.all_vendors %}
  {{ product_vendor | link_to_vendor }}
{% endfor %}

Returns a list of all of the unique product vendors in a collection.

collection.description
{% if collection.description.size > 0 %}
<div>
  {{ collection.description }}
</div>
{% endif %}

Returns the description of the collection.

collection.handle
<ul>
  <li{% unless current_tags %} class="active"{% endunless %}>
    {% if collection.handle %}
    <a href="/collections/{{ collection.handle }}">All</a>
    {% elsif collection.products.first.type == collection.title %}
    <a href="{{ collection.title | url_for_type }}">All</a>
    {% elsif collection.products.first.vendor == collection.title %}
    <a href="{{ collection.title | url_for_vendor }}">All</a>
    {% endif %}
  </li> 
</ul>

Returns the handle of a collection. Whitespaces in the original title are replaced by dashes in the handle. The handle of a collection with the title "Winter Sale" would be "winter-sale".

collection.id
<h1 id="{{ collection.id }}">{{ collection.title }}</h1>

Returns the id of the collection.

collection.image
{% if collection.image %}
  {{ collection.image.src | collection_img_url: 'medium' }}
{% endif %}

Returns the image which represents the collection.

collection.image.alt
<img src="{{ collection.image }}" alt="{{ collection.image.alt}}">

Returns the collection title.

collection.image.src
{% if collection.image %}
  {{ collection.image.src | collection_img_url: 'medium' }}
{% endif %}

Returns the relative URL to the collection image.

collection.next_product
{% if collection.next_product %}
  {{ product.title }}
{% endif %}

This method is available if you scope your product pages to a certain collection. Click here to learn more.

collection.previous_product
{% if collection.previous_product %}
  {{ product.title }}
{% endif %}

This method is available if you scope your product pages to a certain collection. Unsure what this is? Click here to learn more.

collection.products
<ul>
  <li{% unless current_tags %} class="active"{% endunless %}>
    {% if collection.handle %}
    <a href="/collections/{{ collection.handle }}">All</a>
    {% elsif collection.products.first.type == collection.title %}
    <a href="{{ collection.title | url_for_type }}">All</a>
    {% elsif collection.products.first.vendor == collection.title %}
    <a href="{{ collection.title | url_for_vendor }}">All</a>
    {% endif %}
  </li> 
</ul>

Returns all of the products associated with a collection.

collection.products_count
<span>{{ collection.products_count }} {{ collection.products_count | pluralize: 'Item', 'Items' }} total</span>

Returns the number of products in the collection.

collection.template_suffix
<!-- in e.g. index.liquid -->
{% unless collection.template_suffix == 'noprice' %}{{ product.price | money }}{% endunless %}

Returns the name of the collection template assigned to the collection, without the collection. prefix and .liquid extension. If no special template is assigned to the collection, this returns an empty string.

collection.title
<h1>{{ collection.title }}</h1>

Returns the title of the collection.

collection.tags
<p>{{ collection.tags }}</p>

Returns all of the tags in a collection.

collection.url
{% for collection in collections %}
  {% unless collection.all_products_count  == 0 %}
  <a href="{{ collection.url }}"><img src="{{ collection.products.first.featured_image | product_img_url: 'large' }}" alt="{{ collection.title | escape  }}" /></a>
  {% endunless %}
{% endfor %}

Returns the URL of the collection.

Ready to put what you've learned into action?

Build an online store with Shopify Try it Free

Experience the future of retail now

Shopify Point of Sale Try it Free