Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops Shopify在循环时输出多个标记_Loops_Shopify - Fatal编程技术网

Loops Shopify在循环时输出多个标记

Loops Shopify在循环时输出多个标记,loops,shopify,Loops,Shopify,我有一个大约有10个标签的产品,我试着检查一个产品标签是否等于“我们的价格”,它是否显示我们的价格,否则显示销售。我正在使用这个代码: {% for tag in product.tags %} {% if tag == 'OurPrice' %}Our Price: {% else %}Sale: {% endif %} {% endfor %} 我只想让它显示一个或另一个,目前我得到销售:销售:销售:销售:销售:销售:销售:销售:销售:销售:销售:我们的价格:销售: 有没有办法检查一

我有一个大约有10个标签的产品,我试着检查一个产品标签是否等于“我们的价格”,它是否显示我们的价格,否则显示销售。我正在使用这个代码:

{% for tag in product.tags %}
 {% if tag == 'OurPrice' %}Our Price:
 {% else %}Sale:
 {% endif %}
{% endfor %}
我只想让它显示一个或另一个,目前我得到销售:销售:销售:销售:销售:销售:销售:销售:销售:销售:销售:我们的价格:销售:

有没有办法检查一下

编辑:我现在有:

{% assign isOurPrice = False  %}
{% for tag in product.tags  %}
 {% if tag == 'OurPrice' %}Our Price:{% assign isOurPrice = True  %}
 {% endif %}
{% endfor %}
{% if isOurPrice == False %}Sale:
{% endif %}
它显示我们的价格:Sale:它在不应该的时候显示Sale。有什么想法吗

{% $isOurPrice = False;  %}
{% for tag in product.tags  %}
 {% if tag == 'OurPrice' %}Our Price:
 {% $isOurPrice = True; %}
 {% endif %}
{% endfor %}
{% if $isOurPrice == False %}Sale:
{% endif %}
您可以很容易地从
{else
}中删除“Sale:”。如果只是销售价格,则输出


您可以很容易地从
{else
}中删除“Sale:”。如果它只是一个销售价格,则输出。

结果显示shopify提供的代码为-'contains'

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

结果显示shopify提供代码为-“包含”

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

我试过这个,效果更好,但我还是得到了我们的价格:销售:知道为什么吗?@Alex。。cDima没有提到将$isOurPrice翻转到
true
@AlexMurray的行-修复了一行,请再试一次。我尝试了这个,效果更好,但我仍然得到了我们的价格:销售:知道为什么吗?@Alex。。cDima没有提到要将
$isOurPrice
翻转到
true
@AlexMurray的行-修复了一行,请重试