Is there a “break” tag to escape a loop in Liquid?

时间秒杀一切 提交于 2019-12-18 05:27:06

问题


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 %}

回答1:


For future visitors. Above code does work in current Liquid (gem v2.5.1).



来源:https://stackoverflow.com/questions/8028229/is-there-a-break-tag-to-escape-a-loop-in-liquid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!