Thymeleaf
| Company type | Open-source software |
|---|---|
| Industry | Software development, Web development |
Area served | Worldwide |
| Products | Template engine for Java |
| Website | www |
Thymeleaf is a Java-based XML, XHTML, and HTML5 template engine crafted for use in both web (servlet-oriented) and standalone applications. It is particularly effective for rendering XHTML/HTML5 within the view component of MVC frameworks and is capable of processing any XML document offline. Thymeleaf seamlessly integrates with the Spring Framework.
Within web development, Thymeleaf strives to supplant JavaServer Pages (JSP) by utilizing Natural Templates—templates that remain fully functional and displayable directly in web browsers without prior processing.
Thymeleaf is distributed as open-source software under the terms of the Apache License 2.0.
Features
According to the official project site:
- A Java template engine supporting XML, XHTML, and HTML5 formats.
- Operates efficiently in both web and non-web contexts, independent of strict Servlet API reliance.
- Employs modular dialects that introduce functionalities such as expression evaluation and iteration through specialized template tags or attributes.
- Comes with two prepackaged dialects: Standard and SpringStandard (tailored for Spring MVC, sharing syntax conventions with Standard).
- Allows creation of custom dialects by developers.
- Supports a variety of template modes:
- Comprehensive, extensible support for internationalization.
- Configurable, high-speed parsed template cache designed to reduce input/output overhead.
- Automatic DOCTYPE conversion between template DTD declarations and output for optional validation purposes.
- Highly extensible architecture, enabling use as a foundation for template engine frameworks.
- Detailed documentation complemented by sample applications.
Thymeleaf example
Presented below is an example that creates an HTML5 table, iterating over a List<Product> named allProducts to generate rows.
<syntaxhighlight lang="html">
<thead> </thead> <tbody> </tbody>| Name | Price |
|---|---|
| Oranges | 0.99 |
</syntaxhighlight>
Key elements demonstrated:
- Internationalization syntax: #{...}
- Expression evaluation of variables/model attributes: ${...}
- Utility method usage: #numbers.formatDecimal(...)
Moreover, this (X)HTML snippet functions as a natural template, meaning it can be opened directly in browsers without requiring preprocessing.
See also
- Template engine (web)
- JavaServer Pages
- Spring Framework
- FreeMarker
- Apache Velocity
- Template Attribute Language