Search code examples
javaspring-mvcspring-bootthymeleaf

Is it possible to include format of a thymeleaf fragment


I'm looking for a way to include the structure of a thymeleaf fragment into a page.
What i mean by that is as follows:

The fragmend defined as follows:

<div class="container" th:fragment="container">
    <div class="row">
        {the content of the page continues here}
    </div>
</div>

The page template:

<div th:replace="fragments/main:: container">
    {I can continue here for eq, <div class="col-md-5"></div>}
</div>

I dont't know if this is possible but i'm looking for a way to do this.


Solution

  • Due to layout dialect of Thymeleaf, this can be done by adding <th:block layout:fragment="content"/> to desired layout and using this as parent element in your view.