spring-mvcspring-bootappendthymeleafdynamic-text

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


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?


Solution

  • 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>