Questions tagged [thymeleaf]

Thymeleaf is an XML/XHTML/HTML5 template engine (extensible to other formats) that can work both in web and non-web environments. It is better suited for serving XHTML/HTML5 at the view layer of web applications, it can process any XML file even in offline environments. It provides an optional module for integration with Spring MVC, so that you can use it as a complete substitute of JSP in your applications made with this technology, even with HTML5.

Thymeleaf is an XML/XHTML/HTML5 template engine (extensible to other formats) that can work both in web and non-web environments. It is better suited for serving XHTML/HTML5 at the view layer of web applications, but it can process any XML file even in offline environments.

It provides an optional module for integration with Spring MVC, so that you can use it as a complete substitute of JSP in your applications made with this technology, even with HTML5.

Unlike JSP, Thymeleaf is a natural template engine meaning that the file could be directly opened in browsers without having to run the application.

The main goal of Thymeleaf is to provide an elegant and well-formed way of creating templates, allowing to use them also as static prototypes.

Its architecture allows a fast processing of templates, relying on intelligent caching of parsed files in order to use the least possible amount of I/O operations during execution.

Thymeleaf is a Java library.

Additional Thymeleaf Resources:

Resources for Spring Integration:

9206 questions
170
votes
14 answers

How to do if-else in Thymeleaf?

What's the best way to do a simple if-else in Thymeleaf? I want to achieve in Thymeleaf the same effect as

Hello!

Maciej Ziarko
  • 11,494
  • 13
  • 48
  • 69
157
votes
10 answers

Setting up a JavaScript variable from Spring model by using Thymeleaf

I am using Thymeleaf as template engine. How I pass a variable from Spring model to JavaScript variable? Spring-side: @RequestMapping(value = "message", method = RequestMethod.GET) public String messages(Model model) { …
Matteo
  • 1,893
  • 2
  • 14
  • 13
157
votes
26 answers

How to avoid the "Circular view path" exception with Spring MVC test

I have the following code in one of my controllers: @Controller @RequestMapping("/preference") public class PreferenceController { @RequestMapping(method = RequestMethod.GET, produces = "text/html") public String preference() { …
balteo
  • 23,602
  • 63
  • 219
  • 412
145
votes
3 answers

Using data-* attribute with Thymeleaf

Can I set data-* attribute with Thymeleaf? As I understood from Thymeleaf documentation I tried:
Alexandru Severin
  • 6,021
  • 11
  • 48
  • 71
114
votes
11 answers

Using Thymeleaf when the value is null

I have some values in my database which can be null if they have not already been entered. But when I use Thymeleaf in my html, it gives an error when parsing null values. Is there any way to handle this?
serkan
  • 1,237
  • 2
  • 12
  • 14
112
votes
10 answers

Thymeleaf: how to use conditionals to dynamically add/remove a CSS class

By using Thymeleaf as template engine, is it possible to add/remove dynamically a CSS class to/from a simple div with the th:if clause? Normally, I could use the conditional clause as follows: Lorem…
vdenotaris
  • 13,297
  • 26
  • 81
  • 132
102
votes
4 answers

Thymeleaf: Concatenation - Could not parse as expression

I'm having an issue when trying to concat multiple values in my template. According to Thymeleaf here I should simply be able to + them together... 4.6 CONCATENATING TEXTS Texts, no matter whether they are literals or the result of evaluating…
NeilA
  • 1,450
  • 2
  • 12
  • 20
97
votes
3 answers

Process Thymeleaf variable as HTML code and not text

I'm using Thymeleaf to process html templates, I understood how to append inline strings from my controller, but now I want to append a fragment of HTML code into the page. For example, lets stay that I have this in my Java application: String…
Alexandru Severin
  • 6,021
  • 11
  • 48
  • 71
75
votes
4 answers

Thymeleaf th:text - Put a text without removing HTML structures

I'm new in thymeleaf and I try to create a template. My problem is this code:

title Subtitle

I would like to get this output:

TITLE

JohnPortella
  • 1,791
  • 5
  • 21
  • 30
74
votes
4 answers

How to check if list is empty using thymeleaf?

--content--
The above thymeleaf code is not working, where tblUserList is a list. So I want to check whether the list is empty instead of checking its null. How to do that?
Rahul Raj
  • 3,197
  • 5
  • 35
  • 55
72
votes
2 answers

How to loop through Map in Thymeleaf

I am trying to understand how to loop through all entries in a Map in Thymeleaf. I have a domain object being processed by Thymeleaf that contains a Map. How do I loop through the keys and fetch the values ? Thanks.
phil.e.b
  • 2,491
  • 2
  • 16
  • 17
68
votes
5 answers

Thymeleaf construct URL with variable

I have the following code setting a variable in my controller: model.set("type", type); In the thymeleaf view I want to construct a form with action url: /mycontroller/{type} Any ideas how to achieve this? I've read thymeleaf documentation with no…
Chris
  • 923
  • 1
  • 8
  • 11
60
votes
2 answers

How to bind an object list with thymeleaf?

I am having a lot of difficulty with POSTing back a form to the controller, which should contain simply an arraylist of objects that the user may edit. The form loads up correctly, but when it's posted, it never seems to actually post anything.…
benscabbia
  • 17,592
  • 13
  • 51
  • 62
60
votes
3 answers

How to show localization messages with parameters in Spring 3 / Thymeleaf

I'm using Spring 3 and Thymeleaf to make some webpages and I am lost as for how to show messages like this: welcome.message=Hello {0}, welcome! and then replace {0} with the user name inside thymeleaf tags:

Welcome…

Hoffmann
  • 14,369
  • 16
  • 76
  • 91
60
votes
3 answers

setting up a value for a variable name in thymeleaf

I am new to Thymeleaf and converting my Web page from JSP to Thymeleaf. I have a strut tag like this: That variable can be used anywhere in JSP. Is there any such alternatives for this in Thymeleaf?
1
2 3
99 100