Search code examples
thymeleaf

Thymeleaf - How to write th:text?


How can add tag after th:text so that i use br and em. Now here name is showing but after that the br tag and and em tag get skipped

Edited and removed the )

<span class="profile" th:text="${user.name}>
   <br>
   <em class="class_name" th:text="${user.subinfo}></em>
</span>

Solution

  • If you don't want to change the structure of your HTML, you have two alternatives.

    1. Use the <th: block /> tag.

       <span class="profile">
         <th:block th:text="${user.name}" />
         <br>
         <em class="class_name" th:text="${user.subinfo}"></em>
       </span>
      
    2. Use the th:inline="text" attribute.

       <span class="profile" th:inline="text">
         [[${user.name}]]
         <br>
         <em class="class_name" th:text="${user.subinfo}"></em>
       </span>