I want to add multiple classes using condition.
<div th:classappend="x.isTrue ?'class1' " ></div>
I want something like
<div th:classappend="x.isTrue ?'class1' and "y.isTrue ?'class2'" ></div>
You can use literal substitutions to achieve this:
<div th:classappend="|${x.isTrue ? 'class1' : ''} ${y.isTrue ? 'class2' : ''}|"></div>
Another method is to simply wrap your conditions with brackets and concatenate them:
<div th:classappend="${(x.isTrue ? 'class1' : '') + (y.isTrue ? ' class2' : '')}"></div>
Try this solution. It works very well for me.
<span class="oi" th:classappend="${(h.tipo.label =='Sim/Não' ? 'oi-signpost': '') +
(h.tipo.label =='Quantidade' ? 'oi-target': '')+
(h.tipo.label =='Evitar' ? 'oi-shield': '')}"
title="Visualizar"
aria-hidden="true"></span>
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