The collection object has the following attributes:
collection.allproductscount
Returns the total number of products in a collection, even if the collection is filtered.
For the number of products in a filtered collection, use collection.products_count.
For example, for a collection with 24 products in total:
Total products in this collection: {{ collection.all_products_count }}
Total products in this collection: 24
collection.all_tags
Returns a list of all product tags in a collection, even if the collection is filtered. Up to 1,000 tags are returned.
For the tags currently applied, use collection.tags.
collection.all_types
Returns a list of all product types in a collection.
For example, for a collection with products of the types Accessories, Chairs and Shoes:
{% for product_type in collection.all_types %}
{{ product_type | link_to_type }}
{% endfor %}
<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.
For example, for a collection with products of the vendors VersaCommerce, Shirt Company and Montezuma:
{% for product_vendor in collection.all_vendors %}
{{ product_vendor | link_to_vendor }}
{% endfor %}
<a href="/collections/vendors?q=VersaCommerce" title="VersaCommerce">VersaCommerce</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
You can show products of a given type at the URL /collections/types with a query parameter in the format ?q=[type], where [type] is the product type. For example, this URL returns products of the type Shirts:
/collections/types?q=shirts
The query value is case-insensitive, so shirts is the same as Shirts or SHIRTS.
On these pages, collection.current_type returns the type that was queried. This lets you check whether you are on such a page and output the current type:
{% if collection.current_type %}
Currently viewing {{ collection.current_type | downcase }}.
{% endif %}
Currently viewing shirts.
collection.current_vendor
You can show products of a given vendor at the URL /collections/vendors with a query parameter in the format ?q=[vendor], where [vendor] is the product vendor. For example, this URL returns products of the vendor ApparelCo:
/collections/vendors?q=apparelco
The query is case-insensitive, so apparelco is the same as ApparelCo or APPARELCO.
On these pages, collection.current_vendor returns the vendor that was queried. This lets you check whether you are on such a page and output the current vendor:
{% if collection.current_vendor %}
All products by {{ collection.current_vendor }}.
{% endif %}
All products by ApparelCo.
collection.defaultsortby
Returns the default sort order of the collection, set on the collection page in the shop admin.
Possible sort orders:
manualbest-sellingtitle-ascendingtitle-descendingprice-ascendingprice-descendingcreated-ascendingcreated-descending
collection.description
Returns the description of the collection.
collection.featured_image
Returns the featured image of the collection. By default this is the collection image; otherwise VersaCommerce falls back to a suitable image, for example the image of the first product in the collection.
collection.filters
Returns an array of filter objects set up for the collection.
Only filters relevant to the current collection are returned. For collections with more than 1,000 products, the filters are empty.
collection.handle
Returns the handle of the collection.
collection.id
Returns the ID of the collection.
collection.image
Returns the image of the collection, set on the collection page in the shop admin.
Use the URL filter image_url together with the HTML filter image_tag to output the image. Check that the image exists before you output it.
For example:
{% if collection.image %}
{{ collection.image | image_url: width: 2048 | image_tag }}
{% endif %}
collection.next_product
Returns the product object of the next product in the collection, or nil if there is no next product.
For example, output a link to the next product in the collection:
{% if collection.next_product %}
{{ 'Next product' | link_to: collection.next_product.url, collection.next_product.title }}
{% endif %}
collection.previous_product
Returns the product object of the previous product in the collection, or nil if there is no previous product.
For example, output a link to the previous product in the collection:
{% if collection.previous_product %}
{{ 'Previous product' | link_to: collection.previous_product.url, collection.previous_product.title }}
{% endif %}
collection.products
Returns an array of all products in a collection.
Use the paginate tag to set how many products are shown per page, up to a limit of 50.
collection.products_count
Returns the number of products in a collection that match the current view.
For example, if you view a collection filtered by a tag and 6 products have this tag:
{{ collection.products_count }} products
6 products
collection.published_at
Returns the date and time the collection was published.
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. Without a sort_by URL parameter, the value is nil.
For example, for this URL:
/collections/all?sort_by=best-selling
{% if collection.sort_by %}
Sort by: {{ collection.sort_by }}
{% endif %}
Sort by: best-selling
collection.sort_options
Returns an array of sort options for the collection.
For example:
<select id="sort-by">
{% assign sort_by = collection.sort_by | default: collection.default_sort_by %}
{% for option in collection.sort_options %}
<option value="{{ option.value }}" {% if option.value == sort_by %}selected="selected"{% endif %}>{{ option.name }}</option>
{% endfor %}
</select>
<select id="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>
Each option has these properties:
- option.name
- option.value
option.name
The customer-facing label of the sort option. Merchants can edit it in the language editor.
option.value
The value of the sort option that is assigned to the sort_by parameter when a form is submitted.
collection.template_suffix
Returns the name of the custom collection template assigned to the collection, without the collection. prefix and the .liquid extension. Returns nil if no custom template is assigned.
For example, with a collection template named collection.no-price.liquid:
{% if collection.template_suffix %}
{{ collection.template_suffix }}
{% endif %}
no-price
collection.title
Returns the title of the collection.
collection.tags
Returns the tags currently applied to a filtered collection, or nil.
collection.url
Returns the URL of the collection.
More properties
VersaCommerce also provides these properties on the collection object:
| Properties | Returns |
|---|---|
metafields, content, full_url, active, current_tags, current_product_index, all_products, categories, categories_count, all_categories, all_categories_count, vendors, vendors_count, all_vendors_count |
Collection metadata, resource and taxonomy accessors |