Thymeleaf

Last updated
Thymeleaf
Developer(s) Daniel Fernández
Stable release
3.1.3 [1] / December 9, 2024;4 months ago (2024-12-09)
Written in Java
Operating system Cross-platform
Standard(s) XML, XHTML, HTML5
Type Template Engine
License Apache License 2.0
Website www.thymeleaf.org

Thymeleaf is a Java XML/XHTML/HTML5 template engine that can work both in web (servlet-based) and non-web environments. It is better suited for serving XHTML/HTML5 at the view layer of MVC-based web applications, but it can process any XML file even in offline environments. It provides full Spring Framework integration.

Contents

In web applications Thymeleaf aims to be a complete substitute for JavaServer Pages (JSP), and implements the concept of Natural Templates: template files that can be directly opened in browsers and that still display correctly as web pages.

Thymeleaf is open-source software, licensed under the Apache License 2.0.

Features

From the project's website: [2]

Thymeleaf example

The following example produces an HTML5 table with rows for each item of a List<Product> variable called allProducts.

<table><thead><tr><thth:text="#{msgs.headers.name}">Name</th><thth:text="#{msgs.headers.price}">Price</th></tr></thead><tbody><trth:each="prod : ${allProducts}"><tdth:text="${prod.name}">Oranges</td><tdth:text="${#numbers.formatDecimal(prod.price,1,2)}">0.99</td></tr></tbody></table>

This piece of code includes:

Also, this fragment of (X)HTML code can be perfectly displayed by a browser as a prototype, without being processed at all: it is a natural template.

See also

References

  1. "Thymeleaf 3.1: What's new and how to migrate - Thymeleaf".
  2. "Features - Thymeleaf: Java XML/XHTML/HTML5 template engine". Archived from the original on 2011-10-08. Retrieved 2011-10-16. Thymeleaf Features