简体   繁体   English

Shopify(液体)如果产品具有标签,则回显该标签

[英]Shopify (Liquid) if product has a tag, echo that tag

I'm trying to find product tags that meet a condition, and then display those tag(s). 我正在尝试查找符合条件的产品标签,然后显示这些标签。

This gets me all the tags for a product... 这让我获得了产品的所有标签...

{% for tag in product.tags %}
{% if product.tags contains '336699' %}
{{ tag }}
{% endif %}
{% endfor %}

How can I just echo the tags that meet the 'contains' criteria? 我该如何回显符合“包含”条件的标签?

You're almost there. 你快到了。 Use for to iterate the product.tags and contains within a if to match tag with your string literal criteria. 使用for迭代的product.tagscontainsif匹配tag与您的字符串字面量标准。

{% for tag in product.tags %}
    {% if tag contains '336699' %}
        {{ tag }}
    {% endif %}
{% endfor %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM