liquid icon indicating copy to clipboard operation
liquid copied to clipboard

Orphaned `{% break %}` and `{% continue %}`

Open jg-rp opened this issue 2 years ago • 0 comments

Recent commits to the reference implementation have highlighted an incompatibility in the way we handle {% break %} and {% continue %} tags that appear outside of a {% for %} block.

Consider this template:

{%- if true -%}
before
{%- if true %}
hello{% break %}goodbye
{% endif -%}
after
{%- endif -%}
{% for x in (1..3) %}
{{ x }}
{% endfor %}
{% for x in (1..3) %}
{{ x }}
{% endfor %}

Ruby Liquid output in both strict and lax modes:

before
hello

Python Liquid raises a LiquidSyntaxError in strict mode and jumps over the entire outer {% if %} block in lax mode.

1

2

3


1

2

3

Not for the first time, I'm torn between strict compatibility and what I consider to be more natural, expected and consistent behaviour, even for non-dev template authors.

jg-rp avatar Sep 11 '22 07:09 jg-rp