Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

Is there a "break" tag to escape a loop in Liquid?

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 %}
question from:https://stackoverflow.com/questions/8028229/is-there-a-break-tag-to-escape-a-loop-in-liquid

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...