Shopify - 通过 if 语句退出 for 循环

时间:2021-03-19 14:22:06

标签: shopify

我在一家 shopify 商店工作,但不是想销售产品,而是销售预约。 我正在使用名为 Sesami 的 shopify 扩展程序来执行此操作。

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

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

{% 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 保持打开状态,因此会根据过去的约会总数显示我希望向没有即将到来的约会的人多次显示的内容。

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

非常感谢, 朱利安

1 个答案:

答案 0 :(得分:1)

当您希望循环停止当前迭代时,请考虑使用 {% break %}

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