The collection object
The collection
object has the following attributes:
collection.all_products_count
Anchor link to section titled "collection.all_products_count"Returns the total number of products in a collection, even when the collection is filtered.
For example, if a collection has 24 products in total, then the following input would lead to the following output:
collection.all_tags
Anchor link to section titled "collection.all_tags"Returns a list of all product tags in a collection, even when the collection is filtered. A maximum of 1,000 tags can be returned.
collection.all_types
Anchor link to section titled "collection.all_types"Returns a list of all product types in a collection.
For example, if a collection contained products of type Accessories, Chairs, and Shoes, then the following input would lead to the following output:
collection.all_vendors
Anchor link to section titled "collection.all_vendors"Returns a list of all product vendors in a collection.
For example, if a collection contained products from Shopify, Shirt Company, and Montezuma vendors, then the following input would lead to the following output:
collection.current_type
Anchor link to section titled "collection.current_type"You can query for products of a certain type at the /collections/types
URL with a query parameter in the format of ?q=[type]
, where [type]
is your desired product type. For example, the following URL would return products of type Shirts:
If you're on one of these pages, then collection.current_type
returns the current type that's been queried. As such, you can check whether you're on one of these pages, and output the current type like the following:
collection.current_vendor
Anchor link to section titled "collection.current_vendor"You can query for products from a certain vendor at the /collections/vendors
URL with a query parameter in the format of ?q=[vendor]
, where [vendor]
is your desired product vendor. For example, the following URL would return products from the vendor ApparelCo:
If you're on one of these pages, then collection.current_vendor
returns the current vendor that's been queried. As such, you can check whether you're on one of these pages, and output the current vendor like the following:
collection.default_sort_by
Anchor link to section titled "collection.default_sort_by"Returns the default sort order of the collection, which is set in the collection's page of the Shopify admin.
The possible sort orders are:
manual
best-selling
title-ascending
title-descending
price-ascending
price-descending
created-ascending
created-descending
collection.description
Anchor link to section titled "collection.description"Returns the description of the collection.
collection.featured_image
Anchor link to section titled "collection.featured_image"Returns the featured image for the collection. The default is the collection image, and then Shopify will fall back to an appropriate image, such as the featured image of the first product in the collection.
collection.filters
Anchor link to section titled "collection.filters"Returns an array of filter objects that have been set up on the collection.
Only filters relevant to the current collection are returned. Filters will be empty for collections that contain over 1000 products.
collection.handle
Anchor link to section titled "collection.handle"Returns the collection's handle.
collection.id
Anchor link to section titled "collection.id"Returns the ID number of the collection.
collection.image
Anchor link to section titled "collection.image"Returns the collection's image, which is set in the collection's page of the Shopify admin.
You can use the image_url URL filter, and add the image_tag HTML filter to to the image_url
URL filter to output the image. You should also check whether the image exists before trying to output it.
For example:
collection.metafields
Anchor link to section titled "collection.metafields"Returns the collection's metafields.
collection.next_product
Anchor link to section titled "collection.next_product"Returns the product object of the next product in the collection, or nil
if there is no next product.
For example, you can output a link to the next product in the collection:
collection.previous_product
Anchor link to section titled "collection.previous_product"Returns the product object of the previous product in the collection, or nil
if there is no previous product.
For example, you can output a link to the previous product in the collection:
collection.products
Anchor link to section titled "collection.products"Returns an array of all the products in a collection.
You can use the paginate tag to choose how many products to show per page, up to a limit of 50.
collection.products_count
Anchor link to section titled "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 a tag, and there are 6 products with that tag, then the following input would lead to the following output:
collection.published_at
Anchor link to section titled "collection.published_at"Returns the date and time when the collection was published.
You can use a date filter to format the date.
collection.sort_by
Anchor link to section titled "collection.sort_by"Returns the sort order applied to the collection by the sort_by
URL parameter. If there is no sort_by
URL parameter, then the value is nil
.
For example, given the following URL, the following input would lead ot the following output:
collection.sort_options
Anchor link to section titled "collection.sort_options"Returns an array of sorting options for the collection.
For example, the following input would lead to the following output:
Each option has the following attributes:
option.name
Anchor link to section titled "option.name"The customer-facing label for the sort option, which can be edited by merchants in the language editor.
option.value
Anchor link to section titled "option.value"The value of the sort option to be assigned to the sort_by
property in a form submission.
collection.template_suffix
Anchor link to section titled "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.
For example, if you had a collection template called collection.no-price.liquid
, then the following input would lead to the following output:
collection.title
Anchor link to section titled "collection.title"Returns the title of the collection.
collection.tags
Anchor link to section titled "collection.tags"Returns the tags that are currently applied to a filtered collection, or nil
.
collection.url
Anchor link to section titled "collection.url"Returns the URL of the collection.