【问题标题】:Shopify Liquid show custom div after 5th product in collectionShopify Liquid 在集合中的第 5 个产品后显示自定义 div
【发布时间】:2021-04-22 19:45:12
【问题描述】:

我想在我的 shopify 收藏中的第 5 个产品之后显示一个自定义 div。有谁知道我如何在液体中做到这一点?

【问题讨论】:

    标签: collections shopify liquid


    【解决方案1】:

    结束产品的for循环的结尾,放一个条件喜欢

    {% if forloop.index == 5 %}
       <div></div>
    {% endif %}
    

    【讨论】:

      【解决方案2】:

      liquid for loop iteration

      使用limit/offset

      {% for item in array limit: 4 %}
        item less than or equal to 4
      {% endfor %}
      {% for item in array offset: 4 %}
        item greater than 4 (5)
      {% endfor %}
      

      或使用forloop.index

      {% for item in array %}
        {% if forloop.index < 5 %}
          do something for less than 5
        {% else %}
          do something greater than or equal to 5
        {% endif %}
      {% endfor %}
      

      【讨论】:

        猜你喜欢
        • 2014-12-17
        • 1970-01-01
        • 1970-01-01
        • 2021-12-18
        • 1970-01-01
        • 1970-01-01
        • 2018-09-10
        • 1970-01-01
        • 2012-10-27
        相关资源
        最近更新 更多