Closed joel-hamilton closed 6 months ago
I believe the correct behaviour is to render only the first else block in all conditionals (
if
,unless
andcase
).
I agree, possibly with an option to throw an error on superfluous else
blocks.
Shopify/Liquid's {% case %}
/ {% when %}
behaviour gets a little worse if {% when %}
tags appear after {% else %}
.
{% case "x" -%}
{% when "y" -%}
a
{%- else -%}
b
{%- else -%}
c
{%- when "x" -%}
d
{%- when "x" -%}
e
{%- endcase %}
Shopify/Liquid output
bcde
The else
blocks are only rendered if all preceding when
expressions evaluate to false
, but all truthy when
blocks are rendered, no matter the order.
{% case "x" -%}
{% when "x" -%}
a
{%- else -%}
b
{%- else -%}
c
{%- when "x" -%}
d
{%- when "x" -%}
e
{%- endcase %}
Shopify/Liquid output
ade
@jg-rp good catch, liquidjs currently has some strange behaviour around this as well, mainly that truthy when
s will be rendered even after an else
, and the else
won't be rendered. Fixed in #671, that PR has before/after examples.
:tada: This issue has been resolved in version 10.10.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
When there are multiple sequential
else
tags, the content inside of eachelse
branch is rendered.Eg:
liquidjs renders:
Shopify has inconsistent rendering behaviour here, it renders only the first
else
branch insideif
andunless
conditionals, but it renders allelse
blocks inside ofcase
conditionals.I believe the correct behaviour is to render only the first
else
block in all conditionals (if
,unless
andcase
). I'd be happy to put up a fix for this.