Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.36k stars 280 forks source link

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

Open OmarTawfik opened 6 months ago

OmarTawfik commented 6 months ago

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
Keats commented 6 months ago

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

OmarTawfik commented 6 months ago

@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?

Keats commented 6 months ago

If someone does a PR sure

schungx commented 4 months ago

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

OmarTawfik commented 4 months ago

@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 %}
uncenter commented 2 months ago

Duplicate of #862?