Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
OmarTawfik opened this issue Jan 13, 2024 · 6 comments
Open

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

OmarTawfik opened this issue Jan 13, 2024 · 6 comments
Labels

Comments

@OmarTawfik
Copy link

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 Keats added the bug label Jan 13, 2024
@Keats
Copy link
Owner

Keats commented Jan 13, 2024

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

@OmarTawfik
Copy link
Author

@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
Copy link
Owner

Keats commented Jan 14, 2024

If someone does a PR sure

@schungx
Copy link

schungx commented Mar 16, 2024

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

@OmarTawfik
Copy link
Author

@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
Copy link
Contributor

Duplicate of #862?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants