The collection object
The collection
object has the following attributes:
collection.all_products_count
Returns the number of products in a collection. collection.all_products_count
will return the total number of products even when the collection view is filtered.
In comparison, collection.products_count
returns the count of all products in a collection for the current view. For example, if a collection is filtered by tag, collection.products_count
returns the number of products that match the current filter.
Input
{{ collection.all_products_count }} total products in this collection
Output
24 total products in this collection
collection.all_tags
Returns a list of all product tags in a collection. collection.all_tags
will return the full list of tags even when the collection view is filtered.
collection.all_tags
will return at most 1,000 tags.
In comparison, collection.tags
returns all tags for a collection for the current view. For example, if a collection is filtered by tag, collection.tags
returns only the tags that match the current filter.
collection.all_types
Returns a list of all product types in a collection.
Input
{% for product_type in collection.all_types %}
{{ product_type | link_to_type }}
{% endfor %}
Output
<a href="/collections/types?q=Accessories" title="Accessories">Accessories</a>
<a href="/collections/types?q=Chairs" title="Chairs">Chairs</a>
<a href="/collections/types?q=Shoes" title="Shoes">Shoes</a>
collection.all_vendors
Returns a list of all product vendors in a collection.
Input
{% for product_vendor in collection.all_vendors %}
{{ product_vendor | link_to_vendor }}
{% endfor %}
Output
<a href="/collections/vendors?q=Shopify" title="Shopify">Shopify</a>
<a href="/collections/vendors?q=Shirt+Company" title="Shirt Company">Shirt Company</a>
<a href="/collections/vendors?q=Montezuma" title="Montezuma">Montezuma</a>
collection.current_type
Returns the product type on a /collections/types?q=TYPE
collection page. For example, an automatic "Shirts" collection lists all products of type "Shirts" in the store: yourstore.myshopify.com/collections/types?q=Shirts
.
Input
{% if collection.current_type %}
Browse all our {{ collection.current_type | downcase }}.
{% endif %}
Output
Browse all our shirts.
collection.current_vendor
Returns the product vendor on a /collections/vendors?q=VENDOR
collection page. For example, an automatic "ApparelCo" collection lists all products with the vendor "ApparelCo" in the store: yourstore.myshopify.com/collections/vendors?q=ApparelCo
.
Input
{% if collection.current_vendor %}
All products by {{ collection.current_vendor }}.
{% endif %}
Output
All products by ApparelCo.
collection.default_sort_by
Returns the sort order of the collection set in the collection's page in your Shopify admin.
The possible sort orders are:
manual
best-selling
title-ascending
title-descending
price-ascending
price-descending
created-ascending
created-descending
collection.description
Returns the description of the collection.
collection.handle
Returns the collection's handle.
collection.id
Returns the ID number of the collection.
collection.image
Returns the image of the collection.
Use the img_url filter to load the image file from the Shopify content delivery network (CDN). Use an if tag to check for the presence of the image first.
Input
{% if collection.image %}{{ collection.image | img_url: 'medium' }}{% endif %}
Output
//cdn.shopify.com/s/files/1/0087/0462/collections/collection-image_medium.png?v=1337103726
collection.next_product
Returns the next product in the collection. Returns nil
if there is no next product.
{% if collection.next_product %}
{{ 'Next product' | link_to: collection.next_product.url, collection.next_product.title }}
{% endif %}
collection.previous_product
Returns the previous product in the collection. Returns nil
if there is no previous product.
collection.products
Returns all of the products in a collection. You can show a maximum of 50 products per page.
Use the paginate tag to choose how many products are shown per page.
collection.products_count
Returns the number of products in a collection that match the current view. For example, if you are viewing a collection filtered by tag, collection.products_count
will return the number of products that match the chosen tag.
Input
{{ collection.products_count }} products
Output
6 products
collection.published_at
Returns the date and time when the collection was published. You can set this information on the collection's page in your Shopify admin by the Set publish date calendar icon.
You can use a date filter to format the date.
collection.sort_by
Returns the sort order applied to the collection by the sort_by
URL parameter. When there is no sort_by
URL parameter, the value is null
.
Example
/collections/widgets?sort_by=best-selling
Input
{% if collection.sort_by %}
Sort by: {{ collection.sort_by }}
{% endif %}
Output
Sort by: best-selling
collection.sort_options
Returns an array of sorting options for the collection.
Input
<select name="sort_by">
{% for option in collection.sort_options %}
<option value="{{ option.value }}">{{ option.name }}</option>
{% endfor %}
</select>
Output
<select name="sort_by">
<option value="manual">Featured</option>
<option value="best-selling">Best selling</option>
<option value="title-ascending">Alphabetically, A-Z</option>
<option value="title-descending">Alphabetically, Z-A</option>
<option value="price-ascending">Price, low to high</option>
<option value="price-descending">Price, high to low</option>
<option value="created-ascending">Date, old to new</option>
<option value="created-descending">Date, new to old</option>
</select>
option.name
The customer-facing label for the sort option.
You can change the sort option labels shown to customers in the language editor.
option.value
The value of the sort option to be assigned to the sort_by
property in a form submission.
You can identify the current sort option using collection.sort_by.
Example
<option {% if option.value == collection.sort_by %}selected{% endif %} >
...
</option>
collection.template_suffix
Returns the name of the custom collection template assigned to the collection, without the collection.
prefix or the .liquid
extension. Returns nil
if a custom template is not assigned to the collection.
Input
{{ collection.template_suffix }}
Output
no-price
collection.title
Returns the title of the collection.
Input
<h1>{{ collection.title }}</h1>
Output
<h1>Frontpage</h1>
collection.tags
Returns the tags of products in a collection that match the current view. For example, if you are viewing a collection filtered by tag, collection.tags
will return the tags for the products that match the current filter.
collection.url
Returns the URL of the collection.