Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 332
cm_w89 Avatar asked Oct 08 '16 12:10

cm_w89


2 Answers

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 %}
like image 119
Alice Girard Avatar answered Oct 24 '22 09:10

Alice Girard


A safer alternative to avoid rare cases where templates are badly named would be to use request.page_type - see the Shopify docs

{% if request.page_type == 'collection' %}
  Do something
{% endif %}
like image 28
codinghands Avatar answered Oct 24 '22 07:10

codinghands