Fragments


<!-- In most cases a fragment expression is simple
~{template_name::fragment_name} 
~{template_name::fragment_name (arg1, ..., argn) } 
--!>

<!-- insert specified fragment  into host element -->
<div th:<b>insert</b>="~{template_name :: fragment_name}"></div>

<!-- replace host element by specified fragment -->
<div th:<b>replace</b>="~{template_name :: fragment_name}"></div>

<!-- include contents of specified fragment into host element -->
<div th:<b>include</b>="~{template_name :: fragment_name}"></div>

<!-- insert, include, replace expect fragment expression.
Therefore Thymeleaf adds ~{} automatically if they are omitted. 
-->
<div th:<b>insert</b>="template_name :: fragment_name"></div>

<!-- template_name can be omitted, if fragment in current template -->
<div th:<b>insert</b>="template_name :: fragment_name"></div>

<! -- fragment example, generates list of strings --> <ul th:fragment="printList(lst)" th:each="item: ${lst}"> <li th:text="${item}"></li> </ul> <!-- let fragment at the end of template file --> <th:block th:replace=" :: printList(${pageModel.contents.items})"></th:block> <!-- let fragment defined in /fragments/common.html file --> <div th:replace="/fragments/common.html::printList(${pageModel.contents.items})"></div>