What is the difference between the two Thymeleaf attributes: th:include and th:replace?
To define a Thymeleaf fragment, you need to use the th:fragment attribute. You can define fragments either in separate files (recommended) or in a common file. It is also a good practice to place all fragments in a dedicated folder called fragments inside the templates directory ( src/main/resources/templates/ ).
According to documentation if you have this situation:
<div th:include="..."> content here </div> fragment will be placed inside <div> tag.
However when you use replace:
<div th:replace="..."> content here </div> then <div> will be replaced by content.
Thymeleaf can include parts of other pages as fragments (whereas JSP only includes complete pages) using th:include (will include the contents of the fragment into its host tag) or th:replace (will actually substitute the host tag by the fragment’s).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With