Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to pass String.format to thymeleaf template?

I am building thymeleaf template and I must pass to it some String with parameters, like The value equals %s. The thing is that a message can be any so I can not just set Message/Externalizing text in my thymeleaf.properties.

I have tried something like this

    <td th:text="#{(${myObject.stringFormatMessage})(${myObject.param})}"></td>

But it ends up with ??The value equals %s_eng_ENG??. I also changed %s to {0} but the result is almost the same. I can not parse this string before passing to my template because myObject.param has to be bold/colored. Is there any way to do it - pass String.format instead of setting externalized text in my .properties?

like image 802
Dzak Avatar asked Oct 26 '25 08:10

Dzak


1 Answers

You can use it like this:

<td th:text="${T(java.lang.String).format(myObject.stringFormatMessage,myObject.param)}"></td>
like image 80
luboskrnac Avatar answered Oct 28 '25 21:10

luboskrnac



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!