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

Truthyness in conditions #122

Open
Kijewski opened this issue Aug 8, 2024 · 1 comment
Open

Truthyness in conditions #122

Kijewski opened this issue Aug 8, 2024 · 1 comment

Comments

@Kijewski
Copy link
Collaborator

Kijewski commented Aug 8, 2024

Right now, in rinja a condition is considered to match if it evaluates to true or a reference to true. That's a sensible and kinda obvious implementation.

In Jinja, Handlebars, etc. the pythonic concept of "truthiness" is used instead: https://realpython.com/python-boolean/. Everything that could be considered falsy, empty or nullish (0, None, "", [], false) will result in a missed condition.

I think that this behavior is very useful in a templating language. What do you think? Should rinja adopt that concept, too? It would not affect anyone who doesn't (want to) use it. You can write {% if !s.is_empty(), but with this change you could simply write {% if s to get the same result.

@GuillaumeGomez
Copy link
Contributor

GuillaumeGomez commented Aug 8, 2024

I'm shared on this: I love to have things explicit when reading the code. So forcing users to write {% if x != 0 %} instead of {% if x %} is better from this point of view.

But it's also a templating language, so maybe that's what users expect... I'm more on "explicit code" side. ^^'

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

No branches or pull requests

2 participants