【问题标题】:Shopify cycle iteration to simplifyShopify 循环迭代以简化
【发布时间】:2015-02-24 17:28:57
【问题描述】:

我正在尝试使用 shopify 中的循环将一个类添加到前 4 个 div,然后将一个新类添加到第二个 4 个 div,然后将一个新类添加到第三组 div。

不要像这样输入

      {% cycle '<div class="1">', '<div class="1">', '<div class="1">', '<div class="1">', '<div class="2">', '<div class="2">', '<div class="2">', '<div class="2">', '<div class="3">', '<div class="3">', '<div class="3">', '<div class="3">', %}

有没有办法迭代这个,这样我就可以减少打字,类继续像 20,所以打字很多?

【问题讨论】:

    标签: loops logic shopify liquid


    【解决方案1】:

    你可以试试这样的

    {% for i in (1..20) %}
      <div class="{% if forloop.index < 5 %} class1{% endif %}{% if forloop.index >=5 and forloop.index < 9 %} class2{% endif %}{% if forloop.index >=9 and forloop.index <13 %}class3{% endif %}">class{{ forloop.index }}</div>
     {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 2013-05-29
      • 2020-01-28
      • 1970-01-01
      • 2021-03-15
      • 2020-05-20
      • 2010-10-22
      • 1970-01-01
      • 2022-06-24
      • 2017-06-10
      相关资源
      最近更新 更多