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

No boolean operators for conditions #311

Open
gerdint opened this issue Oct 25, 2024 · 6 comments
Open

No boolean operators for conditions #311

gerdint opened this issue Oct 25, 2024 · 6 comments

Comments

@gerdint
Copy link

gerdint commented Oct 25, 2024

I know there is "all" and "any" in conditions, but there doesn't seem to be an "and" (or "or") operator for instance?

Like: {% if condition-a and condition-b %} (or perhaps "if and conditon-a condition-b")

Right now I need to nest two if-tags, which is not so nice..

@yogthos
Copy link
Owner

yogthos commented Oct 25, 2024

It shouldn't be too hard to add that in, the relevant code is here

(defn render-if [render context-map condition first-block second-block]

Any chance you'd be up to do a PR for this? :)

@gerdint
Copy link
Author

gerdint commented Oct 25, 2024

Yeah guess not. In my case I also need nested conditions, like:

{% if (not condition-a) and condition-b %}

is there support for nested conditions right now? It does not seem like it. It's basically just about a general expression evaluator.

@gerdint
Copy link
Author

gerdint commented Oct 25, 2024

Seems like even the Django template language supports this?

https://www.geeksforgeeks.org/boolean-operators-django-template-tags/

@gerdint gerdint changed the title No logical operators for conditions No boolean operators for conditions Oct 25, 2024
@yogthos
Copy link
Owner

yogthos commented Oct 25, 2024

Nested conditions would be a bit trickier as it'd need a bit of a redesign as I recall. The original idea was to provide fairly minimal support for logic as you can always do fancier transforms in Clojure before passing the data to Selmer.

@gerdint
Copy link
Author

gerdint commented Oct 25, 2024

All right. Well just one level deep conditions (but ideally including support for not operator in subexpressions) would perhaps be a good compromise (and be on par with Django's language). But unless I get quite bored in the near future I have to admit this is not a high priority for me, and my current project is a one man show where I much prefer Hiccup anyway. And as you say there is always the possibility to do more logic in Clojure behind the scenes.

@yogthos
Copy link
Owner

yogthos commented Oct 25, 2024

Yeah, I find Hiccup is generally preferable as well. The main use for Selmer is to provide something familiar for people coming from other languages. It also can be useful outside HTML templating since it's agnostic regarding the content it processes.

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

No branches or pull requests

2 participants