In this tutorial, we'll discuss:
Let's briefly look into these 6 template modes:
- What is Thymeleaf?
- What kind of templates can Thymeleaf process?
- What is a Thymeleaf template?
- Thymeleaf Engine
- Where's a Thymeleaf template processed?
Learn Thymeleaf at https://www.javaguides.net/p/thymeleaf-tutorial.html
What is Thymeleaf?
Thymeleaf is a modern server-side Java template engine for both web and standalone environments, capable of processing HTML, XML, JavaScript, CSS, and even plain text.
The main goal of Thymeleaf is to provide an elegant and highly-maintainable way of creating templates.
It's commonly used to generate HTML views for web apps.
Thymeleaf template engine is commonly used with the Spring MVC framework to develop web applications.
Learn Spring boot at https://www.javaguides.net/p/spring-boot-tutorial.html
Learn Spring MVC at https://www.javaguides.net/p/spring-mvc-tutorial.html
What kind of templates can Thymeleaf process?
Out-of-the-box, Thymeleaf allows you to process six kinds of templates, each of which is called a Template Mode:
- HTML
- XML
- TEXT
- JAVASCRIPT
- CSS
- RAW
Let's briefly look into these 6 template modes:
- The HTML template mode will allow any kind of HTML input, including HTML5, HTML 4 and XHTML.
- The XML template mode will allow XML input.
- The TEXT template mode will allow the use of a special syntax for templates of a non-markup nature. Examples of such templates might be text emails or templated documentation.
- The JAVASCRIPT template mode will allow the processing of JavaScript files in a Thymeleaf application.
- The CSS template mode will allow the processing of CSS files involved in a Thymeleaf application.
- The RAW template mode will simply not process templates at all. It is meant to be used for inserting untouched resources (files, URL responses, etc.) into the templates being processed.
What is a Thymeleaf template?
- Well, Thymeleaf template can be an HTML page with some Thymeleaf expressions.
- It can also include dynamic content from Thymeleaf expressions.
For example, here is the HTML page with Thymeleaf attributes and expressions:
We use Thymeleaf expressions to access Java variables, objects, and Spring beans.Thymeleaf Engine
Thymeleaf Engine will parse Thymeleaf Template. It uses Java model data to replace the positions marked on the Thymeleaf Template to create a new text in the HTML page.
Where's a Thymeleaf template processed?
- Well, in web applications, the Thymeleaf is processed on the server.
- Results are included in the HTML and returned to the browser.
In Spring MVC web applications, the Spring MVC controller returns views (Thymeleaf template) as the result and that will be again rendered on the browser.
The below screenshot shows a typical request flow in Spring MVC application and the Spring MVC controller returns views (Thymeleaf template) as the result and that will be again rendered on the browser:
Related Thymeleaf Tutorials and Examples
- Introducing Thymeleaf | Thymeleaf Template | Thymeleaf Template Engine
- Thymeleaf Example with Spring Boot
- How to Add CSS and JS to Thymeleaf
- Add Bootstrap CSS to Thymeleaf
- How to handle null values in Thymeleaf?
- How to Loop a List by Index in Thymeleaf
- Thymeleaf Array Example - Array Index, Array Iteration
- Thymeleaf Enums Example
- Thymeleaf If Else Condition Example
- Thymeleaf Switch Case Example
Comments
Post a Comment
Leave Comment