Collection
The collection
object has the following attributes:
In this article
- collection.all_tags
- collection.all_types
- collection.all_products_count
- collection.all_vendors
- collection.current_type
- collection.current_vendor
- collection.default_sort_by
- collection.description
- collection.handle
- collection.id
- collection.image
- collection.next_product
- collection.previous_product
- collection.products
- collection.products_count
- collection.published_at
- collection.template_suffix
- collection.title
- collection.tags
- collection.url
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_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 all tags for 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 }} Sản phẩm
Output
10 Sản phẩm
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=haravan" title="Haravan">Haravan</a>
<a href="/collections/vendors?q=juno" title="Juno">Juno</a>
<a href="/collections/vendors?q=vinamilk" title="vinamilk">Vinamilk</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.myharavan.com/collections/types?q=Shirts
.
</p>
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/vendores?q=VENDOR
collection page. For example, an automatic "Haravan Vendor" collection lists all products with the vendor "Haravan Vendor" in the store: yourstore.myharavan.com/collections/vendors?q=haravan-vendor
.
</p>
Input
{% if collection.current_vendor %}
All products by {{ collection.current_vendor }}.
{% endif %}
Output
All products by Haravan Vendor.
collection.default_sort_by
Returns the sort order of the collection, which is set on the collection's page in your Haravan 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 collection image. Use the img_url filter to load the image file from the Haravan content delivery network (hstatic). Use an if tag to check for the presence of the image first. </p>
Input
{% if collection.image %}{{ collection.image | img_url: 'medium' }}{% endif %}
Output
//hstatic.net/206/1000001206/1000068949/slideshow_1.jpg
collection.next_product
Returns the URL of the next product in the collection. Returns nil
if there is no next product.
You can use collection.next_product
and collection_previous product
with the within filter to create "next" and "previous" links in the product.liquid template.
collection.previous_product
Returns the URL of the previous product in the collection. Returns nil
if there is no previous product.
You can use collection.next_product
and collection_previous product
with the within filter to create "next" and "previous" links in the product.liquid template.
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 }} sản phẩm
Output
10 sản phẩm
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 Haravan admin by the Set publish date calendar icon.
You can use a date filter to format the date.
collection.template_suffix
Returns the name of the custom collection template assigned to the collection, without the collection.
prefix or the .liquid
suffix. 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>Haravan Collections</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.