diff --git a/spring-thymeleaf/pom.xml b/spring-thymeleaf/pom.xml
index a13f1de4c7..960b358fe2 100644
--- a/spring-thymeleaf/pom.xml
+++ b/spring-thymeleaf/pom.xml
@@ -5,186 +5,192 @@
spring-thymeleaf
0.1-SNAPSHOT
war
-
- 1.8
-
- 4.3.3.RELEASE
- 3.0.1
-
- 1.7.12
- 1.1.3
-
- 3.0.1.RELEASE
-
- 1.1.0.Final
- 5.1.2.Final
+
+ 1.8
+
+ 4.3.3.RELEASE
+ 3.0.1
+
+ 1.7.12
+ 1.1.3
+
+ 3.0.1.RELEASE
+
+ 1.1.0.Final
+ 5.1.2.Final
-
- 3.5.1
- 2.6
- 2.19.1
- 1.4.18
-
+
+ 3.5.1
+ 2.6
+ 2.19.1
+ 1.4.18
+
-
-
-
- org.springframework
- spring-context
- ${org.springframework-version}
-
-
-
- commons-logging
- commons-logging
-
-
-
-
- org.springframework
- spring-webmvc
- ${org.springframework-version}
-
-
-
- org.springframework.security
- spring-security-web
- 4.1.3.RELEASE
-
-
- org.springframework.security
- spring-security-config
- 4.1.3.RELEASE
-
-
-
- org.thymeleaf
- thymeleaf
- ${org.thymeleaf-version}
-
-
- org.thymeleaf
- thymeleaf-spring4
- ${org.thymeleaf-version}
-
-
-
- org.slf4j
- slf4j-api
- ${org.slf4j.version}
-
-
- ch.qos.logback
- logback-classic
- ${logback.version}
-
-
-
- org.slf4j
- jcl-over-slf4j
- ${org.slf4j.version}
-
-
-
- org.slf4j
- log4j-over-slf4j
- ${org.slf4j.version}
-
-
-
- javax.servlet
- javax.servlet-api
- ${javax.servlet-version}
- provided
-
-
-
- javax.validation
- validation-api
- ${javax.validation-version}
-
-
- org.hibernate
- hibernate-validator
- ${org.hibernate-version}
-
-
+
+
+
+ org.springframework
+ spring-context
+ ${org.springframework-version}
+
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+ org.springframework
+ spring-webmvc
+ ${org.springframework-version}
+
+
+
+ org.springframework.security
+ spring-security-web
+ 4.1.3.RELEASE
+
+
+ org.springframework.security
+ spring-security-config
+ 4.1.3.RELEASE
+
+
+
+ org.thymeleaf
+ thymeleaf
+ ${org.thymeleaf-version}
+
+
+ org.thymeleaf
+ thymeleaf-spring4
+ ${org.thymeleaf-version}
+
+
+
+ nz.net.ultraq.thymeleaf
+ thymeleaf-layout-dialect
+ 2.0.4
+
+
+
+ org.slf4j
+ slf4j-api
+ ${org.slf4j.version}
+
+
+ ch.qos.logback
+ logback-classic
+ ${logback.version}
+
+
+
+ org.slf4j
+ jcl-over-slf4j
+ ${org.slf4j.version}
+
+
+
+ org.slf4j
+ log4j-over-slf4j
+ ${org.slf4j.version}
+
+
+
+ javax.servlet
+ javax.servlet-api
+ ${javax.servlet-version}
+ provided
+
+
+
+ javax.validation
+ validation-api
+ ${javax.validation-version}
+
+
+ org.hibernate
+ hibernate-validator
+ ${org.hibernate-version}
+
+
-
- org.springframework
- spring-test
- 4.1.3.RELEASE
- test
-
+
+ org.springframework
+ spring-test
+ 4.1.3.RELEASE
+ test
+
-
-
- org.springframework.security
- spring-security-test
- 4.1.3.RELEASE
- test
-
+
+
+ org.springframework.security
+ spring-security-test
+ 4.1.3.RELEASE
+ test
+
-
-
- junit
- junit
- 4.12
- test
-
+
+
+ junit
+ junit
+ 4.12
+ test
+
-
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ ${java-version}
+ ${java-version}
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ ${maven-war-plugin.version}
+
+ false
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
+
+
+
+
+
+
+ org.codehaus.cargo
+ cargo-maven2-plugin
+ ${cargo-maven2-plugin.version}
+
+ true
+
+ jetty8x
+ embedded
+
+
+
+
+
+ 8082
+
+
+
+
+
+
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
- ${java-version}
- ${java-version}
-
-
-
- org.apache.maven.plugins
- maven-war-plugin
- ${maven-war-plugin.version}
-
- false
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- ${maven-surefire-plugin.version}
-
-
-
-
-
-
-
-
- org.codehaus.cargo
- cargo-maven2-plugin
- ${cargo-maven2-plugin.version}
-
- true
-
- jetty8x
- embedded
-
-
-
-
-
- 8082
-
-
-
-
-
-
-
diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java
index 444b780673..ab048bdd87 100644
--- a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java
+++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java
@@ -22,6 +22,9 @@ import org.thymeleaf.templateresolver.ITemplateResolver;
import com.baeldung.thymeleaf.formatter.NameFormatter;
import com.baeldung.thymeleaf.utils.ArrayUtil;
+import nz.net.ultraq.thymeleaf.LayoutDialect;
+import nz.net.ultraq.thymeleaf.decorators.strategies.GroupingStrategy;
+
@Configuration
@EnableWebMvc
@@ -70,6 +73,7 @@ public class WebMVCConfig extends WebMvcConfigurerAdapter implements Application
private TemplateEngine templateEngine(ITemplateResolver templateResolver) {
SpringTemplateEngine engine = new SpringTemplateEngine();
+ engine.addDialect(new LayoutDialect(new GroupingStrategy()));
engine.setTemplateResolver(templateResolver);
return engine;
}
diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/LayoutDialectController.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/LayoutDialectController.java
new file mode 100644
index 0000000000..28a38ce30b
--- /dev/null
+++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/LayoutDialectController.java
@@ -0,0 +1,16 @@
+package com.baeldung.thymeleaf.controller;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+@Controller
+public class LayoutDialectController {
+
+ @RequestMapping(value = "/layout", method = RequestMethod.GET)
+ public String getNewPage(Model model) {
+ return "content.html";
+ }
+
+}
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/content.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/content.html
new file mode 100644
index 0000000000..1184e28e13
--- /dev/null
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/content.html
@@ -0,0 +1,16 @@
+
+
+
+Layout Dialect Example
+
+
+
+ This is a custom content that you can provide
+
+
+
+
\ No newline at end of file
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/listStudents.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/listStudents.html
index a894e41e88..c7d17a4f66 100644
--- a/spring-thymeleaf/src/main/webapp/WEB-INF/views/listStudents.html
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/listStudents.html
@@ -6,7 +6,7 @@
-
+
+
+
+
+ Your page content goes here
+
+
+
+