How to have multiple condition in an th:if tag ?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to have multiple condition in an th:if tag ?

brnrd
Hello,

I have a text to render in 3 different possible color, based on the value of the variable.

So the code I've made so far to test the value is :

    th:if="${evaluation} & gt; 50"
    th:if="${evaluation} & lt; 30"


And that works well.

But the third test is for values between those two. So I tried :

    th:if="(${evaluation} & lt; 49) & and; (${evaluation} & gt; 29)"

(note that the space after the & are only to escape the html conversion of this post)

but it's not working, I've got this error while parsing :

    org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "(${evaluation} < 49) ∧ (${evaluation} > 29)" (/property.html:41)

Of course, these lines are between tags since the first two are working properly.

Maybe the and operand is not correct, but the documentation is not really explicit on those operands.


All ideas are welcome, thanks already for your help.
Reply | Threaded
Open this post in threaded view
|

Re: How to have multiple condition in an th:if tag ?

Zemi
Administrator
Hello,

are you using the standard expression language (ONGL) or the Spring integration (SpEL)?

In the second case, you could read the reference documentation at
   http://forum.thymeleaf.org/How-to-have-multiple-condition-in-an-th-if-tag-tp4025931.html

With SpEL your expression would be
    th:if="${evaluation < 49 and evaluation > 29}"

Reply | Threaded
Open this post in threaded view
|

Re: How to have multiple condition in an th:if tag ?

Eric Francis
I believe your link goes to this same page.
Reply | Threaded
Open this post in threaded view
|

Re: How to have multiple condition in an th:if tag ?

Zemi
Administrator
Reply | Threaded
Open this post in threaded view
|

Re: How to have multiple condition in an th:if tag ?

brnrd
Thanks, I succed to make it work with your help.

The right way to do it for me was th:if="${evaluation & lt; 50 and evaluation & gt; 29}"

Thanks again.