仅在集合页面上显示项目

时间:2014-10-29 03:18:41

标签: shopify liquid

在shopify上,我想要一系列代码代码来自theme.liquid,只显示在集合页面上,无论使用哪个模板(我都有一些自定义集合模板)。我该如何编写代码来执行此操作?

目前我正在使用。

{% 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

我将来会添加带有新自定义模板的新集合,但这意味着我必须复制更多相同内容才能涵盖新的集合模板。

我如何拥有涵盖所有集合模板/集合页面的代码行

1 个答案:

答案 0 :(得分:1)

改为使用contains运算符:

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

在此处查看有关包含的更多信息: http://docs.shopify.com/themes/liquid-documentation/basics/operators#contains