2

What I'm trying to do is get the view content fragment to include its contents into the base.html layout, but I want it to replace that div, and only display the 3 section tags, and not the div as the parent element.

I'm not getting any errors as it is, but instead of <div th:replace="${view} :: content"></div> becoming those 3 section tags, it turns into <div><section>...</section><section>...</section><section>...</section></div>. I want it to just be <section>...</section><section>...</section><section>...</section>. Maybe I misunderstood the documentation for replace, but I understood that it should replace the div with the content of the fragment.

Here is the layout file, base.html:

<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
    <head>
        ...
    </head>
    <body>
        <!--main menu-->
        <!-- Static navbar --> 
        <header class="navbar navbar-inverse navbar-default navbar-fixed-top navbar-transparent">
           ...
        </header>

        <!--end main menu-->

        <div th:replace="${view} :: content"></div>

        <footer>
            ...
        </footer>
    </body>
</html>

Here is the view file, default/view.html:

<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
    <body>
        <div th:fragment="content">
          <section>
              ...
          </section>      
          <section>
              ...
          </section> 
          <section>
              ...
          </section> 
        </div>
    </body>
</html>
xil3
  • 16,305
  • 8
  • 63
  • 97

1 Answers1

0

I figured it out.

I just had to replace that div with th:block in both of the templates.

xil3
  • 16,305
  • 8
  • 63
  • 97