Skip to content
Advertisement

SpringMVC with Bootstrap and Thymeleaf pages decoration

I am working in: “SpringMVC 5”, with “Twitter Bootstrap 4” html pages, and “Thymeleaf 3” templating, in IntelliJ EAP (latest version) and Tomcat9, Maven

The structure of my project:

JavaScript

I am using these tutorials: https://www.baeldung.com/spring-thymeleaf-fragments https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#template-layout

I have my page (home.html). I have my template (template.html). According to the 2nd tutorial:

  • I inserted the “menubar” into the “template” (this insert must work, because I inserted the menubar directly to the “home.html” and it was inserted successfuly)
  • Question that I cannot solve from what they say into the 2nd tutorial: How I “decorate” my “home.html” according the “template.html”. I mean, how I use the template to decorate according it all my pages? I used the following in the “home.html” but it is not working:
JavaScript

My files are:

“home.html”

JavaScript

“menubar.html”

JavaScript

“template.html”

JavaScript

“WebConfig.java”

JavaScript

In my pom (some of it):

JavaScript

Please some one help. Thanks in advance

Advertisement

Answer

Hey finally I found solution:

Step 1

I put the page and the layout in the same folder:

JavaScript

Step 2

In “home.html” I added the “layout:decorate”

JavaScript

In “template.html” I changed the “layout:fragment”

JavaScript

In the “WebConfig.java” I deleted the “viewResolver() method” and I changed the others like following:

JavaScript

But… A problem remains. I cannot keep my pages and my layout in different folders. If I do it with the previous structure and put: layout:decorate=”~{layout/template}” the page is displayed as a blank page.

Any solution and idea from you it would be perfect for me. A part of the solution is found though.

=========== Update: ===========

Solution in the last part is found. I had a mistake in the “template.html”. I should put it as: “layout/fragments/menubar.html :: menubar” with the structure:

JavaScript

And the code will be:

JavaScript

I will put it as a solution, in some hours when the system will let me.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement