4

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?

Dzak
  • 201
  • 2
  • 12
  • 1
    https://stackoverflow.com/questions/20789441/how-to-show-localization-messages-with-parameters-in-spring-3-thymeleaf – Martin Frey Mar 28 '19 at 07:06
  • This solution works when I set `welcome.message` in my `.properties` with any message, not when I pass it from my application – Dzak Mar 28 '19 at 07:13

1 Answers1

5

You can use it like this:

<td th:text="${T(java.lang.String).format(myObject.stringFormatMessage,myObject.param)}"></td>
luboskrnac
  • 23,973
  • 10
  • 81
  • 92