Thomas Schmidt
Thomas Schmidt

Reputation: 1378

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

Upvotes: 3

Views: 685

Answers (1)

Robert Ellis
Robert Ellis

Reputation: 734

Another way to do this would be

th:attr="class=|a ${x ? 'b' : 'c'}|"

Upvotes: 6

Related Questions