Hello!
Imagine I have a product that belongs to more than one collection. I’d like to have the list of the product’s collections displayed in the product description, so that users can quickly click on one of the collections to explore further.
To display the list of product TAGS, I’m using the following code:
{% if product.tags.size > 0 %}
Tags: {% for tag in product.tags %}
{% assign tag_coll = ‘/collections/all/’ | append: tag %}
{{ tag | capitalize | link_to: tag_coll }}{% unless forloop.last %},{% endunless %}
{% endfor %}
{% endif %}
How should I amend it to display the list of COLLECTIONS that a product belongs to? For example, this code from @Niraj_singh displays the first colelction in the list, but how to display the entire list?
{% assign pro_collection = product.collections.first %}
{% if pro_collection %}
This product is part of my {{ pro_collection.title | link_to: pro_collection.url }} Collection
{% endif %}
UPDATED:
The previous solution worked, but I found out that it didn’t work for 2-word collections, like “board games”: the collection link turns spaces to “-”, while the code suggested turns spaces into “%20”. What we need is a short addition that replaces spaces with “-”, too:
IF YOU NEED THE COLLECTIONS LISTED WITH COMMAS, USE: