Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect

A dialect for Thymeleaf that allows you to use layout/decorator templates to style your content.

  • 3.3.0
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

Thymeleaf Layout Dialect

Build Status codecov Maven Central

A dialect for Thymeleaf that lets you build layouts and reusable templates in order to improve code reuse.

Documentation

All of the latest documentation on the layout dialect can be found on the dedicated docs website at https://ultraq.github.io/thymeleaf-layout-dialect/

For version 1 docs which supported Thymeleaf 2, the classic readme still exists over on https://github.com/ultraq/thymeleaf-layout-dialect/tree/1.4.0

What does it do?

The Thymeleaf Layout Dialect adds the ability to decorate templates - automatically for the <head> section of an HTML template, and explicitly through extension points that developers can add to their templates. This all adds up to create layouts that can be extended in a manner similar to classical inheritence.

For example, given a common layout.html file, set some shared static assets in the <head> and define extension points in the body with the layout:fragment processor:

<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
  <title>Layout page</title>
  <script src="common-script.js"></script>
</head>
<body>
  <header>
    <h1>My website</h1>
  </header>
  <section layout:fragment="content">
    <p>Page content goes here</p>
  </section>
</body>
</html>

Create a content template that will define its own title, static resources, and replacements for those extension points. Link the page to the layout by using the layout:decorate processor at the root element of the page which will instruct Thymeleaf to decorate the layout with this template:

<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
  layout:decorate="~{layout.html}">
<head>
  <title>Content page</title>
  <script src="content-script.js"></script>
</head>
<body>
  <section layout:fragment="content">
    <p>This is a paragraph from the content page</p>
  </section>
</body>
</html>

When Thymeleaf processes your content template, the resulting HTML will be:

<!DOCTYPE html>
<html>
<head>
  <title>Content page</title>
  <script src="common-script.js"></script>
  <script src="content-script.js"></script>
</head>
<body>
  <header>
    <h1>My website</h1>
  </header>
  <section>
    <p>This is a paragraph from the content page</p>
  </section>
</body>
</html>

Learn more

Check out the getting started guide to learn how to add the layout dialect to your Thymeleaf project, or read up on the many processors for more ways of how the layout dialect can help you build your templates.

FAQs

Package last updated on 17 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc