Thymeleaf 3 Upgrade - th:insert differs from th:include

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Thymeleaf 3 Upgrade - th:insert differs from th:include

xtian
The migration guide states that "th:include" is now called "th:insert", but the two differ because th:include skips the fragment tag, while th:insert keeps it.

Example:

The following fragment in "modalNotify.html"

  <div th:fragment="modal" class="modal fade child">
    <div class="modal-dialog">

when th:included with

   <div th:include="/modalNotify :: modal" class="modal fade parent"></div>

gives

  <div class="modal fade parent">
      <div class="modal-dialog">

but when th:inserted with

   <div th:insert="/modalNotify :: modal" class="modal fade parent"></div>
       
gives

  <div class="modal fade parent">
    <div class="modal fade child">
      <div class="modal-dialog">

This is a real problem when using the layout: dialect (https://ultraq.github.io/thymeleaf-layout-dialect/MigrationGuide.html) because layout:include now behaves like th:insert, therefore breaking compatibility.