Home > Mobile >  Thymeleaf - How to display text not included in th:text
Thymeleaf - How to display text not included in th:text

Time:10-23

I would like to display the name of a user using thymeleaf. Here is the html tag that I'm using:

<h1 th:text="${username}"></h1>

I want it to display this: Hello, User

Given username is a string "User". I tried something like this:

<h1 th:text="${username}">Hello, </h1>

But it didn't work. How can I fix it?

CodePudding user response:

I personally prefer to just use an additional tag.

<h1>Hello, <span th:text="${username}" /></h1>

or literal substitution

<h1 th:text="|Hello, ${username}|"></h1>

as quoting strings just adds more complexity.

CodePudding user response:

Try this:

<h1 th:text="'Hello, '   ${username}"></h1>

Source: https://www.wimdeblauwe.com/blog/2021/01/11/string-concatenation-with-thymeleaf/

  • Related