shopify I need to check if current page is a collection page and not a single product page

cm_w89 picture cm_w89 · Oct 8, 2016 · Viewed 9.8k times · Source

I am trying to check if my current page is a collection page not a single product page in some collection.

I mean for example if someone goes to collection page of shoes then I can check using collection.handle == 'Shoes' but if I select a product from that page then it will still give me true But I want my condition to be true on if it is collection page. Thanks for your Help!

Answer

Alice Girard picture Alice Girard · Oct 8, 2016

Use this simple way with template:

{% if template contains 'collection' %}
    Do something
{% endif %}

As Shopify evolves you can now use this:

{% if template.name == 'collection' %}
    Do something
{% endif %}