wsgg
wsgg

Reputation: 984

show item only on collection pages

on shopify, i want a line of code of code from theme.liquid to show only on collection pages regardless the template used (i have a few custom collection templates). how do i write the code to do this?

currently i'm using.

{% if template == 'collection.home' %}
<div class="filter_btn">
  loremipsum 
</div>
{% endif %}

{% if template == 'collection.featured' %}
<div class="filter_btn">
  loremipsum 
</div>
{% endif %}

similar duplicate of code above for other collection template

i will be adding new collections with new custom templates in the future, but that means i have to duplicate more of the same to cover new collection templates..

how can i have a line of code that covers all collection templates / collection pages

Upvotes: 0

Views: 422

Answers (1)

Jason
Jason

Reputation: 896

Use the contains operator instead:

{% if template contains 'collection' %}
  I am likely a collection template
{% endif %}

See more about contains here: http://docs.shopify.com/themes/liquid-documentation/basics/operators#contains

Upvotes: 1

Related Questions