【发布时间】:2018-04-07 12:03:15
【问题描述】:
我正在显示产品标签。如果用户点击All products filter 那么它将只显示第一个标签。如果用户点击任何当前标签,那么它将显示在当前标签名称上。
{% for tag in product.tags %}
{% if current_tags contains tag %}
<a class="link" href="/collections/{{ collection.handle }}">{{ tag | link_to_tag: tag }}</a>
{% else %}
<a class="link" href="/collections/{{ collection.handle }}">{{ product.tags[0] | link_to_tag: tag }}</a>
{% endif %}
{% endfor %}
以上代码显示所有标签
我的逻辑是
for(display all tag){
if(clicked current tag){
display current tag name which is clicked
}
else{
display first tag name
}
}
【问题讨论】:
-
是的,否则部分不起作用。我的意思是它正在显示所有标签。我只需要单个标签或第一个标签
标签: if-statement tags shopify product