Thymeleaf: <label> to have dynamic text concatenated with static text Spring MVC

Vasudev picture Vasudev · Sep 8, 2017 · Viewed 15.8k times · Source

I'm trying to append some text to a dynamic text as shown below:

<label th:text="Hello ${worldText}"></label>

But the UI throws:

TemplateProcessingException: Could not parse as expression: "Hello ${worldText}

Does anyone know how can I achieve this?

Answer

Benjamin Sch&#252;ller picture Benjamin Schüller · Sep 8, 2017

An easy solution would be to insert a span to the label:

<label>Hello <span th:text="${worldText}"></span></label>

But i would prefer to combine text and variables like this:

<label th:text="'Hello' + ${worldText}"></label>