【问题标题】:How to check for a product within a Shopify collection using Liquid?如何使用 Liquid 检查 Shopify 集合中的产品?
【发布时间】:2017-09-28 09:41:35
【问题描述】:
我有一个产品对象:
assign rel_products = collection.products
如何检查此对象中的特定产品?最好是id。我正在做这个检查,所以我可以在 for 循环中continue:
{% if rel_products contains related_product.id %}
{% continue %}
{% endif %}
上面的代码不起作用。
【问题讨论】:
标签:
arrays
collections
shopify
liquid
【解决方案1】:
我对液体不是很熟悉,但是您的代码 sn-p 中的问题看起来像是您将集合分配给变量 rel_products,因此您必须循环遍历它,然后在每次迭代中检查 id。可能是这样的?
{% for product in rel_products %}
{% if product contains 'Id you want to check' %}
{% continue %}
{% endif %}
{% endfor %}
【解决方案2】:
我认为这可能是您需要的解决方案。
{% assign rel_products = collection.products %}
{% for product in rel_products %}
{% if product.id == 12345789 %} //123456789 is just an example
<!-- Something you want to do -->
{% endif %}
{% endfor %}