是否有“休息”?标签来逃避 Liquid 中的循环?
如何跳出 Liquid 中的循环(主要是 for 循环)?我尝试过 {% break %}
,但失败并显示保存文件时出错:未知标记“break”。
我正在努力实现类似的目标:
var variants = [];
{% for item in cart.items %}
{% if item.product.handle == "handle-name" %}
variants = {{item.product.variants | json}};
{% break %} // won't work
{% endif %}
{% endfor %}
How do I break out of loop in Liquid, mainly a for-loop? I've tried {% break %}
, but that fails with There were errors saving your file: Unknown tag 'break'.
I'm trying to achieve something like:
var variants = [];
{% for item in cart.items %}
{% if item.product.handle == "handle-name" %}
variants = {{item.product.variants | json}};
{% break %} // won't work
{% endif %}
{% endfor %}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于未来的访客。上面的代码确实在当前的 Liquid (gem v2.5.1) 中工作。
因此,您可以简单地执行以下操作:
For future visitors. Above code does work in current Liquid (gem v2.5.1).
So, you can simply do: