Collection

From Shopify Wiki

Jump to: navigation, search

The liquid variable _collection_ has the following attributes:

Contents

collection.id

Returns the id of this collection

collection.title

Returns the title of this collection

collection.handle

Returns this collection's handle, which is by default its title in lowercase. 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.description

Returns the description of this collection

collection.products

Returns a collection of all products that are associated with this collection which match the current view. This takes into account things like paginate and selected tags. You can access each product by e.g. a for-iteration:

{% for product in collection.products %}
   {{ product.title }}
{% endfor %}

Note: To filter the products by tags, you can append "?constraint=tagname1+tagname2" to the URL of that collection and only products that have both tags will be returned. This also works with collection.products_count.

collection.products_count

Returns a count of all of the products in this collection which match the current view. This takes into account things like paginate and selected tags.

collection.all_products

Returns all products that are associated with this collection.

Note: The default limit is set to 50 products, to overwrite this limit and return more products you have to wrap the for loop in a paginate tag.

collection.all_products_count

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

collection.tags

Returns all tags of all products on in this particular collection which match the current view. This means that if the current view is filtered to only products with a certain tags this variable will hold all the tags these remaining products actually have.

<ul>
  {% for tag in tags %}  
  <li>{{ '+' | link_to_add_tag: tag }} {{ tag | link_to_tag: tag }}</li>
  {% endfor %}
</ul>

collection.all_tags

This shows all tags associated with the collection.

collection.next_product and collection.previous_product

These methods are available if you scope your product pages to a certain collection. For a discussion, read How To Navigate Within A Collection

collection.url

Returns the url for the specific collection.

Personal tools