Search code examples
javatemplateslayoutthymeleaf

Thymeleaf - Include content of fragment


Thymeleaf fragment:

<div th:fragment="assets">
    <script src="myscript"></script>
    <script src="myscript2"></script>
</div>

This piece of code inserts the fragment:

<div th:replace="fragments/assets :: assets"></div>


How to include only content without the wrapper?

<script src="myscript"></script>
<script src="myscript2"></script>

Solution

  • try the below

    <div th:fragment="assets" th:remove="tag">
        <script src="myscript"></script>
        <script src="myscript2"></script>
    </div>