I am using Thymeleaf 3 within a Spring Boot application. Currently I am in a situation where I want to use a message expression inside an EL expression (Spring EL).
First use case: trim the message
data:title="${#{message.key}.trim()}
Second use case: conditionally create an attribute with a message as its value
data:title="${condition ? #{message.key} : ''}
Both examples will produce a syntax error, because #{
is not an allowed start of an expression.
Any ideas how to achieve what I want?
In both cases you'll want to use the #messages
utility object.
data:title="${#messages.msg('key').trim()}"
data:title="${condition ? #messages.msg('key') : ''}"
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