Difference between Thymeleaf include and replace?
Taken from baeldung
There are three basic ways to include content from a fragment:
- insert – inserts content inside the tag
- replace – replaces the current tag with the tag defining the fragment
- include – this is deprecated but it may still appear in a legacy code
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).