Shopify 在循环时输出多个标签

Shopify outputs multiple tags when looping

我有一个产品有大约 10 个标签,我正在尝试检查产品标签是否等于 'OurPrice',如果它显示我们的价格,否则显示销售。我正在使用此代码:

{% for tag in product.tags %}
 {% if tag == 'OurPrice' %}Our Price:
 {% else %}Sale:
 {% endif %}
{% endfor %}

我只想让它显示一个或另一个,目前我得到 Sale:Sale:Sale:Sale:Sale:Sale:Sale:Sale:Sale:Sale:Sale:Our Price:Sale:

有没有办法检查这个?

编辑:我现在有:

{% assign isOurPrice = False  %}
{% for tag in product.tags  %}
 {% if tag == 'OurPrice' %}Our Price:{% assign isOurPrice = True  %}
 {% endif %}
{% endfor %}
{% if isOurPrice == False %}Sale:
{% endif %}

显示我们的价格:促销:它在不应该显示促销时显示促销。有什么想法吗?

{% $isOurPrice = False;  %}
{% for tag in product.tags  %}
 {% if tag == 'OurPrice' %}Our Price:
 {% $isOurPrice = True; %}
 {% endif %}
{% endfor %}
{% if $isOurPrice == False %}Sale:
{% endif %}

您可以非常轻松地从 { else} 中删除 'Sale:'。只输出销售价。

原来是 shopify 优惠代码 - 'contains'

{% if product.tags contains "OurPrice" %}
  Our Price:
{% else %}
  Sale:
{% endif %}