首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Shopify - Exit for循环通过if语句

问Shopify - Exit for循环通过if语句
EN

Stack Overflow用户
提问于 2021-03-19 22:22:07
回答 1查看 103关注 0票数 0

我在一家shopify商店工作,但不是试图销售产品,而是约会。我使用一个名为Sesami的shopify扩展来做到这一点。

在customer/account.iquid页面中,我希望向没有未来约会的人显示下一个(或多个)即将到来的约会和不同的信息。

我一直在尝试使用以下代码来实现这一点:

代码语言:javascript
复制
{% if customer.orders != blank %}
 {% for order in customer.orders %}
 {%- for line_item in order.line_items -%}
 {% for property in line_item.properties limit:1 %}
  {% assign today_date = 'now' | date: '%s' %}
  {% assign pre_date = property.last | date: '%s' %}
   {% if pre_date >= today_date %}
    {{ line_item.product.title | link_to: line_item.product.url }}
    {% for property in line_item.properties limit:1 %}
     {% if property != blank %}
      {{ property.last | date: format: 'abbreviated_date' }}
      {{ 'customer.orders.at' | t }} 
     {% endif %}
    {%- endfor -%}
    {% for property in line_item.properties offset:1 %}
     {{ property.last }}
    {%- endfor -%}
    {{ line_item.image |  img_url: 'small' | img_tag }}
    {{ order.fulfillment_status_label }}
   {% endif %}  
  {% endfor %}
  {%- endfor -%}
  {% endfor %} 
{% else %}
Content for people with no booking at all
{% endif %}

但问题是forloop保持打开,因此根据过去的约会总数,我希望向没有即将到来的约会的人多次显示我希望显示的内容。

我想有一种更简单的方法可以做到这一点,我希望你能帮我找到它!

非常感谢,朱利安

EN

回答 1

Stack Overflow用户

发布于 2021-03-19 23:29:19

当你想让循环停止当前的迭代时,考虑使用{% break %}。

https://shopify.github.io/liquid/tags/iteration/#break

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66709931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档