How to have multiple condition in an th:if tag using thymeleaf

brnrd picture brnrd · Apr 15, 2013 · Viewed 75.8k times · Source

I have a text to render in three different possible colors using thymeleaf.

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

th:if="${evaluation} > 50"
th:if="${evaluation} < 30"

And that works well.

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

th:if="(${evaluation} < 49) ∧ (${evaluation} > 29)"

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

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "(${evaluation} < 49) &and; (${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 of thymeleaf is not really explicit on those operands.

All ideas are welcome!

Update: I got the answer from the thymeleaf forum. The way to do it is:

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

Problem solved!

Answer

brnrd picture brnrd · May 8, 2013

I got the answer from the thymeleaf forum. The way to do it is :

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

Problem solved !