Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf: Add to existing values instead of replacing them

Is there a way to tell Thymeleaf to add parameters to a tag instead of overriding them?

Example:

 <div class="a" th:class=${x ? 'b' : 'c'}>

Should result in either

<div class="a b">

or

<div class="a c">

Regards

like image 222
Thomas Schmidt Avatar asked Nov 30 '25 02:11

Thomas Schmidt


1 Answers

Another way to do this would be

th:attr="class=|a ${x ? 'b' : 'c'}|"
like image 61
Manoj Ramanan Avatar answered Dec 05 '25 00:12

Manoj Ramanan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!