tera icon indicating copy to clipboard operation
tera copied to clipboard

[bug] for loop `else` doesn't strip whitespaces

Open OmarTawfik opened this issue 1 year ago • 6 comments

The whitespace markers {%- and -%} around for and endfor strip whitespace correctly, but not else:

{%- for x in y -%} // picked up before/after

{%- else -%} // useless/ignored

{%- endfor -%} // picked up before/after

OmarTawfik avatar Jan 13 '24 14:01 OmarTawfik

Probably already works in v2 but I'll have to add it as a testcase

Keats avatar Jan 13 '24 17:01 Keats

@Keats the bug exists in the latest published 1.19.0. Given that v2 has no expected release date/still WIP, do you think it is possible to fix it in v1 in the meantime?

OmarTawfik avatar Jan 14 '24 05:01 OmarTawfik

If someone does a PR sure

Keats avatar Jan 14 '24 06:01 Keats

What does else in a for loop do, just out of curiosity?

schungx avatar Mar 16 '24 11:03 schungx

@schungx https://keats.github.io/tera/docs/#for

Lastly, you can set a default body to be rendered when the container is empty:

{% for product in products %}
  {{loop.index}}.{{product.name}}
{% else %}
  No products.  
{% endfor %}

OmarTawfik avatar Mar 16 '24 14:03 OmarTawfik

Duplicate of #862?

uncenter avatar May 22 '24 17:05 uncenter