Could somebody, please, help with Thymeleaf? I need to create a template layout and I’ve got stuck with <div th:fragment="content"></div>
. The point is layout:fragment
doesn’t replace code on the dashboard page. By the way, other processors like layout:decorate
or th:replace
works well. I’m using Intellij IDEA with Spring 2.5.4.
#dashboard.html
<!DOCTYPE html> <html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{admin/share/template.html}"> <head> <title>Admin dashboard</title> </head> <body> <div layout:fragment="content"> <h1>Admin Dashboard</h1> </div> </body> </html>
#template.html
<!DOCTYPE html> <html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> <head> <style th:replace="~{admin/share/style}"></style> </head> <body> <div class="app-container app-theme-white body-tabs-shadow fixed-sidebar fixed-header"> <div th:replace="/admin/share/header"></div> <div class="app-main"> <div th:replace="/admin/share/sidebar"></div> <div class="app-main__outer"> <div class="app-main__inner"> <div th:fragment="content"> <p>Page content goes here</p> </div> </div> </div> </div> <div th:replace="/admin/share/js"></div> </div> </body> </html>
#pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>nz.net.ultraq.thymeleaf</groupId> <artifactId>thymeleaf-layout-dialect</artifactId> <version>3.0.0</version> </dependency>
#Thymeleaf.class
@Configuration public class Thymeleaf { @Bean public LayoutDialect layoutDialect() { return new LayoutDialect(); } }
UPDATE:
The issue is solved. Just need to use layout:fragment
instead of th:fragment
=)
Advertisement
Answer
Just need to use layout:fragment
instead of th:fragment
=)