kakabali
kakabali

Reputation: 4033

Thymeleaf add custom data attribute with message resource value

I have a requirement where I need to insert the value to custom data tag using thymeleaf. The code for doing it using

  data-th-attr="${data-custom=#messages.msg('test')}"

as well as

  th:attr="data-custom=${#messages.msg('test')}"

I am unable to get the value in both the cases.

ultimately the parsing should be like data-custom="test"

here test is key for the value test in a properties file

Upvotes: 1

Views: 3548

Answers (2)

kakabali
kakabali

Reputation: 4033

By using the

 data-th-attr="data-custom=#{test}" 

or By using

 th:attr="data-custom=#{test}"

helped me out, here test is the key for the value in message resource the issue was with the intellij IDEA IDE, it was having a bug that was showing me an unnecessary error.

Upvotes: 3

sitakant
sitakant

Reputation: 1878

Use th:attr="data-custom=#{key.for.message}" , this should work.
then after parsing the Expression,
data-custom="value.for.message"

Upvotes: 1

Related Questions