Search code examples
thymeleaf

Why the Html text inside html element does not concatenate with the Thyme-leaf text? code be


I am new to thyme leaf , and i am trying to concatenate the text from the java code with the html . i show below.

<h1 th:utext="${message}" id="font">
        Hello does not concat with message.
        </h1>

Solution

  • That's just not how thymeleaf works. th:text and th:utext replace the contents of the tag.

    The th:text attribute ... sets the result as the body of the host tag, effectively replacing the ... text we see in the code.

    There are plenty of ways to accomplish what you want though. For example, to append at the end:

    <h1 id="font">
        Hello does concat with message.
        <span th:utext="${message}" />
    </h1>
    

    Or

    <h1 th:utext="|Hello does concat with message. ${message}|" id="font" />