Thymeleaf - custom attribute

Pavel picture Pavel · Feb 15, 2014 · Viewed 11.9k times · Source

I need to set custom attribute (data-validation-matches-message) value from messages resources.

<input data-validation-matches-message="Text from messages resources" />

I can receive and print messages resources value as:

<p th:text="#{user.notfound}"></p>

But how I can set this value for a custom attribute (data-validation-matches-message)?

UPD (I use this)

<input th:attr="data-validation-matches-message=#{user.notfound}"/>

Answer

Jaroslav Z&#225;ruba picture Jaroslav Záruba · Jan 4, 2015

Since Thymeleaf 2.1 you can do this:

<a data-th-attr="data-groupid=${somevalue}, data-groupname=${someothervalue}">...</a>

source