Skip to content

Latest commit

 

History

History
124 lines (101 loc) · 3.08 KB

README.adoc

File metadata and controls

124 lines (101 loc) · 3.08 KB

spring-boot-thymeleaf-layouts Build Status

This repository contains example of using thymeleaf layouts (nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect) In addition here also demonstrated webflux interceptor (WebFilter)

HOW TO:

  • add dialect dependency

  • add java configuration

@Configuration
class ThymeleafLayoutConfig {
  @Bean fun layoutDialect() = LayoutDialect()
}
  • add common layout src/main/resources/templates/layouts/default.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
  <title>Common title</title>
  <!-- common resources -->
  <link rel="shortcut icon" th:href="@{/favicon.ico}" href="/favicon.ico" type="image/x-icon">
  <link rel="stylesheet" th:href="@{/common/styles.css}" href="/common/styles.css">
</head>
<body>
<!-- common content -->
<header>
  <ul>
    <li><a th:href="@{/}" href="/">Home page</a></li>
    <li><a th:href="@{/info}" href="/info">Info page</a></li>
  </ul>
</header>
<!-- app-content / app-footer to be replaced in each view -->
<section layout:fragment="app-content">
  <p>Common layout fragment</p>
</section>
<footer>
  <h5>App footer</h5>
  <p layout:fragment="app-footer">Common app footer</p>
</footer>
</body>
</html>
  • add views src/main/resources/templates/index.html or src/main/resources/templates/info.html with proper declaration: <html layout:decorate="~{layouts/default}">

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layouts/default}">
<head>
  <title>

    title per view

  </title>
  <link rel="stylesheet" th:href="@{/additional-styles.css}" href="/additional-styles.css">
</head>
<body>
<section layout:fragment="app-content">
  <h3>Info header h3</h3>
  <p>

    section content per view

  </p>
</section>
<footer>
  <p layout:fragment="app-footer">

    footer content per view

  </p>
</footer>
</body>
</html>

build / run

gradle
./gradlew
java -jar build/libs/*.jar
bash build/libs/*.jar

./gradlew build composeUp
./gradlew composeDown
maven
./mvnw
java -jar target/*.jar
bash target/*.jar

./mvnw; ./mvnw com.dkanejs.maven.plugins:docker-compose-maven-plugin:1.0.1:up
./mvnw com.dkanejs.maven.plugins:docker-compose-maven-plugin:1.0.1:down

links:

generated by jvm yeoman generator