Thymeleaf Tutorial

March 07, 2020 No comments Thymeleaf Tutorial Spring Boot

Thymeleaf is a Java-based template engine that allows you to process several types of documents such as XML, XHTML or HTML5. The engine provides a very pleasent way to inject logic into the templates. It uses XML tags and attributes so even without running the application server we can check how the template will look like when it will be rendered. The engine allows to a parallel work of the backend and frontend developers on the same view.

Thymeleaf attributes

Thymeleaf is an engine based on XML attributes. The engine evaluates values from attributes to build a DOM tree. Basing on attributes allows treating templates as simple static HTML documents that can be displayed in the browser without running any web application server. This is one of the reasons why Thymeleaf is so awesome.

Constructing URLs in Thymeleaf (th:href)
Using th:each in Thymeleaf (th:each)
Using conditions in Thymeleaf (th:if, th:switch)
Create data-* attribute with Thymeleaf (th:attr)
Working with Forms in Thymeleaf (th:action, th:field)
Using Enums in Thymeleaf (T)
Working with local variables in Thymeleaf (th:with)

Thymeleaf utility methods

Thymeleaf comes with many useful utility classes that will help you in formatting and manipulating content on the templates. The engine provides methods for formatting string, parsing URI/URL, aggregating items in collections and processing common Java objects like Maps, Lists or Booleans.

#uris

Thymeleaf utility methods for URI/URL

#arrays

Thymeleaf utility methods for Arrays

#bools

Thymeleaf utility methods for Booleans

#objects

Thymeleaf utility methods for Objects

#strings

Thymeleaf utility methods for Strings

#numbers

Thymeleaf utility methods for Numbers

#calendars

Thymeleaf utility methods for Calendar

#dates

Thymeleaf utility methods for Dates

#lists

Thymeleaf utility methods for Lists

#messages

Thymeleaf utility methods for messages

25+ UI Components with Thymeleaf

Thymeleaf can be used with many different web components written in all available JavaScript frameworks. This section presents commonly used HTML components working with and handled by the Thymeleaf engine.

{{ message }}

{{ 'Comments are closed.' | trans }}