Extend A View With Thymeleaf

is it possible extend a shared view with thymeleaf?

I saw that is possible use framents but is not what I want. Instead I want something similar to .NET MVC, with something like @RenderBody() and another view that extend the shared view by including the shared view.

Answers


You can use the Thymeleaf Layout Dialect to extend a view.

Layout page

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
    ...
    <body layout:fragment="body">
      ...
    </body>
</html>

Content page

In your content page, you refer to the layout (decorator) page using the layout:decorator attribute.

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
  layout:decorator="layout.html">
    ...
    <body layout:fragment="body">
      <p>Actual page content</p>
    </body>
</html>

It is possible to have multiple fragments in one page.

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
    ...
    <body>
      <div layout:fragment="content"></div>
      <footer layout:fragment="footer"></footer>
    </body>
</html>

Need Your Help

How to get the DataSet to recognize the table names from stored procedure?

c# sql-server stored-procedures dataset

I have a stored procedures which returns about 5 tables and I am returning them something like this:

Confusion in static methods in asp.net

c# .net ajax

I have a website. And I'm making some ajax calls to static webmethods wrote in the codebehind. Will it create any problem if more number of users simultaneously loads the website. Being static, there