thymeleaf spring standard dialect: using template

746 Views Asked by At

Hello I have some problems with templating pages. I am returning from controller a view called list:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="layout/template">
    <div layout:fragment="pageContent">
        <p>LIST</p>
    </div>
</html>

And I would like to put this into template where I have a lot of html stuff and: <div layout:fragment="pageContent">Demo static page content</div>

But I am getting in web browser only list view.

How to put one view returned from controller to template using SpringStandardDialect?

1

There are 1 best solutions below

7
On

So if i understand correctly, you want to inject that fragment which is called pageContent into some other html page (lets call it main.html for sake of it.

First thing to do is change the div in list to the following:

<div th:fragment="pageContent">
      <p>LIST</p>
</div>

then in your main.html you would call the fragment via:

<div th:include="list::pageContent"></div>

or

<div th:replace="list::pageContent"></div>

Btw "list::pageContent" indicates that its in base folder, if its located in folder called example then it would be "example/list:pageContent".

here is the great example on Thymeleaf website: http://www.thymeleaf.org/doc/usingthymeleaf.html#including-template-fragments

Hope this helps, if not let me know.