【问题标题】:using Liquid how can I get the first N variants in a for loop使用 Liquid 如何在 for 循环中获得前 N 个变体
【发布时间】:2013-10-08 21:05:05
【问题描述】:

我想为每个产品获取前 2 个变体(总共 4 个)。这似乎很简单,但我正在努力寻找一种方法。

我当前的代码很简单:

{% for variant in product.variants %}
        {% if variant.available == true %}
            <span class="index-price">
                           ${{ variant.price | money_without_currency }} 
                        <span class="hyphen">-</span>
        {% endif %}
    {% endfor %}

非常感谢任何帮助。

【问题讨论】:

    标签: shopify liquid


    【解决方案1】:

    试试这个:

    {% for variant in product.variants limit: 2 %}
        {% if variant.available == true %}
            <span class="index-price">
                           ${{ variant.price | money_without_currency }} 
                        <span class="hyphen">-</span>
        {% endif %}
    {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-28
      • 1970-01-01
      • 2014-06-24
      • 1970-01-01
      • 1970-01-01
      • 2020-05-13
      相关资源
      最近更新 更多