【问题标题】:How can I check for more than 1 product with same name?如何检查超过 1 个同名产品?
【发布时间】:2015-01-05 10:38:06
【问题描述】:

我需要检查是否有两个或多个同名产品,以便添加 if/else 语句。所以我的思路是:

{% if product.title == product.title %}

{% if product.title.size > 1 %}

但这似乎不对。

谢谢!

【问题讨论】:

    标签: shopify liquid


    【解决方案1】:

    您是在寻找特定的产品标题,还是任何重复的产品标题?如果您要与给定的产品名称进行比较,不妨试试这样的方法:

    {% assign found_duplicate = false %}
    
    {% for p in products %}
        {% if p.title == product.title %}
            {% assign found_duplicate = true %}
        {% endif %}
    {% endfor %}
    
    {% if found_duplicate == true %}
        ...
    {% endif %}
    

    【讨论】:

      猜你喜欢
      • 2020-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-15
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      • 2013-08-26
      相关资源
      最近更新 更多