Any template that leaves a for loop early loses the rest of the page. After a break, or after a continue on the last pass, everything that follows the loop silently fails to render: totals, footers, even the rest of the…
Any template that leaves a for loop early loses the rest of the page. After a break, or after a continue on the last pass, everything that follows the loop silently fails to render: totals, footers, even the rest of the outer loop when loops are nested. No error is raised.
{% for i in (1..5) %}{{ i }}{% break %}{% endfor %} after.{% for i in (1..3) %}{{ i }}{% continue %}x{% endfor %} done.{% for row in rows %}{% for cell in row %}{% if cell == 0 %}{% break %}{% endif %}{{ cell }}{% endfor %};{% endfor %} with rows set to [[1,0,2],[3,4,0],[5,6,7]].1 after123 done1;34;567;11231break or continue are fine.continue in an earlier pass is fine when the last pass completes normally: {% for i in (1..4) %}{% if i == 2 %}{% continue %}{% endif %}{{ i }}{% endfor %} gives 134.break should end only the loop it is in.Adapted from harttle/liquidjs (MIT).
Visible test command
TZ=UTC npx --no-install jest --ci --coverage=falseThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
break-stops-rest-of-template
Changes under src/ are evaluated.