I am on the product info page and would like to know if its possible to get the current collection that the product is in so that i can do some stuff. How can i get the current collection? I have tried collection.title and it doesnt show anything.
I am on the product info page and would like to know if its possible to get the current collection that the product is in so that i can do some stuff. How can i get the current collection? I have tried collection.title and it doesnt show anything.
3
Answers
In order to get the CURRENT collection, you MUST have the collection handle in your URL.
So for example if the product URL is something like so
/collections/COLLECTION_HANDLE/products/PRODUCT_HANDLE
you will have access to the current collection.In your case since you don’t have access to the collection title I assume that your URL is just
/products/PRODUCT_HANDLE
.This means that you are generating the wrong URL’s ( not wrong, but not full ). You must look for
product.url
in your collection and add the filterwithin: collection
.So your collection liquid code should look something like this
This will force your product url to include the collection URL as well.
Try it if your URL in this format “/collections/COLLECTION_HANDLE/products/PRODUCT_HANDLE”
Try This:
This product is in the {{ collection.title }} Collection.
Although there might be many collections product assigned but the better way to get the current collection title that is in URL
Note: Using this code you can do stuff on your product page only if collection is in the URL.