I'm using Spring Boot 2.3.3.RELEASE with Thymeleaf. From the Thymeleaf documentation it's not clear to me when I must use the ${} delimiters in a Thymeleaf expression.
For example I had this in my template, and it was working:
<div th:title="${doTest() ? 'foo' : 'bar'}" />
But then I reread the docs and I see that I could use this:
<div th:title="${doTest()} ? 'foo' : 'bar'" />
But the ? … : … ternary operator is an operator, so thus the whole thing is an expression. So why don't I need the ${} around the whole attribute value?
Could I also do this?
<div th:title="doTest() ? 'foo' : 'bar'" />
What about this?
<div th:title="'foo'" />
Why one and not the other?
What about this? Can I use just a bare true?
<div th:if="true">…</div>
Or do I need expression delimiters?
<div th:if="${true}">…</div>
Here's another example: I see this in the documentation:
<li th:text="${item.description}" …
But can I just use th:text="item.description"? What do the braces do for me?
I also see this:
th:each="item : ${items}"
Can I just use th:each="item : items" instead? Why wouldn't Thymeleaf know to evaluate items without the braces in ${items}?
Surely there must be some simple rule for when I need ${}, but it's not immediately obvious.