当前标记在Shopify中显示多个标记名称

编程入门 行业动态 更新时间:2024-10-23 21:36:08
本文介绍了当前标记在Shopify中显示多个标记名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在显示产品标签。如果用户点击所有产品过滤器,那么它将仅显示第一个单个标签。如果用户点击任何当前标记,则它将显示在当前标记名称上。

I am displaying the product tags. If the user clicked on All products filter then It will display only first single tag. If the user clicks on any current tag then it will display on the current tag name.

{% 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 %}

以上代码是显示所有标签

Above code is displaying all the tag

我的逻辑是

for(display all tag){ if(clicked current tag){ display current tag name which is clicked } else{ display first tag name } }

推荐答案

您可以通过以下方式实现:

You can achieve it with the following:

{% assign product_tags = products | map: 'tags' %} {% if product_tags contains current_tags %} <a class="link" href="/collections/{{ collection.handle }}">{{ current_tags | link_to_tag: current_tags }}</a> {% else %} {% assign first_tag = product.tags | first %} <a class="link" href="/collections/{{ collection.handle }}">{{ first_tag | link_to_tag: first_tag }}</a> {% endif %}

尝试在您所需的位置更新此代码并告诉我你是否得到了结果。

Try updating this code in your required place and let me know whether you got the result.

更多推荐

当前标记在Shopify中显示多个标记名称

本文发布于:2023-11-12 12:39:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581515.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标记   多个   名称   Shopify

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!