Sequential `else` tags all render
joel-hamilton opened this issue ยท 3 comments
When there are multiple sequential else
tags, the content inside of eachelse
branch is rendered.
Eg:
<p>If</p>
{% if false %}
don't show
{% else %}
show
{% else %}
don't show
{% endif %}
<p>Unless</p>
{% unless true %}
don't show
{% else %}
show
{% else %}
don't show
{% endunless %}
<p>Case</p>
{% case true %}
{% when false %}
don't show
{% else %}
show
{% else %}
don't show
{% endcase %}
liquidjs renders:
<p>If</p>
show
don't show
<p>Unless</p>
show
don't show
<p>Case</p>
show
don't show
Shopify has inconsistent rendering behaviour here, it renders only the first else
branch inside if
and unless
conditionals, but it renders all else
blocks inside of case
conditionals.
I believe the correct behaviour is to render only the first else
block in all conditionals (if
, unless
and case
). I'd be happy to put up a fix for this.
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
๐ This issue has been resolved in version 10.10.1 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐