当前位置:网站首页>How to use nested tags in thymeleaf3 Tags

How to use nested tags in thymeleaf3 Tags

2022-06-24 15:38:00 Exclusive rainy days

Suppose in a Thymeleaf3 Template , You want to use the following operations . In one use Thymeleaf3 Under the label of grammar , Nesting uses another Thymeleaf3 Grammar tags .

<h1 th:text="${header.title}" >
   title
   <small th:text="${header.subtitle}" >Subtitle</small>
</h1>

The result you want to generate is

<h1>
   title
   <small>Subtitle</small>
</h1>

But the actual result is

<h1>
   title
</h1>

The feasible scheme is as follows :

  1. Use the inline scheme
<h1 th:inline="text" >
   [[${header.title}]]
   <small th:text="${header.subtitle}">Subtitle</small>
</h1>
  1. Or use the remove tag scheme
<h1>
    <span th:text="${header.title}" th:remove="tag">title</span>
    <small th:text="${header.subtitle}" >Subtitle</small>
</h1>

Reference documents :

  1. templates - Thymeleaf th:text - Put a text without removing HTML structures - Stack Overflow
原网站

版权声明
本文为[Exclusive rainy days]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241321404737.html