Timeline change variable
I am new to Thymeleaf and I need to do something like this:
<div th:each="element : ${list}" th:with="test=false"> <div th:each="element2 : ${list2}"> <div th:if="element2.name == 'someName'"> <div th:with="test=true">test changed</div> </div> </div> <div th:text="${test}"></div> </div> If I try this code, I see "test modified", but my test variable is always false
+8
Dawid k
source share1 answer
A with an expression creates or overrides a local variable .
This means that the changed variable is only available inside the element declared with the expression.
In your case, the test output is written outside the div modifier, so you get the result from the outside.
+1
Martin Frey
source share