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?
Thymeleaf offers a set of Spring integrations that allow you to use it as a fully-featured substitute for JSP in Spring MVC applications.
In this case, you should use th:text . For example, Username: <p th:text=${account. username}>Username will be rendered here</p> . Note that, the text inside p tag won't be shown.
It provides full integration with Spring Framework. It applies a set of transformations to template files in order to display data or text produced by the application. It is appropriate for serving XHTML/HTML5 in web applications. The goal of Thymeleaf is to provide a stylish and well-formed way of creating templates.
Variable expressions are OGNL expressions –or Spring EL if you're integrating Thymeleaf with Spring. *{} is used for selection expressions. Selection expressions are just like variable expressions, except they will be executed on a previously selected object. #{} is used for message (i18n) expressions.
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>
Another straightforward solution is
<label th:text="${'Hello ' + worldText}"></label>
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