I am new in 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 changed" but my variable test is always false
A with expression creates or overrides a local variable.
That means that the modified variable is only accessible inside the element you declared the with expression on.
In your case the output of test is written outside of the modification div so you get the result from outside.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With