Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a thymeleaf dialect to spring boot?

Tags:

I'm using Spring Boot and I want to add the IE conditional comments Thymeleaf dialect.

I've included it in my maven pom.xml, but it's not working. How do I tell Thymeleaf to use it?

like image 955
xdhmoore Avatar asked May 08 '14 02:05

xdhmoore


People also ask

What is dialect in Thymeleaf?

Dialects. Thymeleaf Dialects are sets of features we can use in your templates. These features include: Processing logic specified via processors that apply to attributes in our tags (or tags themselves).

How do I add Thymeleaf?

We can implement Thymeleaf template engine by adding spring-boot-starter-thymeleaf dependency in our application's pom. xml file. Spring Boot configures template engine to read template file from /resource/templates.


1 Answers

NOTE: Before trying this, note that later versions of Spring Boot include some of the common dialects out of the box. See @Robert Hunt's answer. Otherwise:

There is an example here of adding Dialect beans, which Spring Boot will automagically detect and use (see the LayoutDialect code and the dialects member of the ThymeleafDefaultConfiguration class). In your case, add the following in of one of your @Configuration classes:

@Bean public ConditionalCommentsDialect conditionalCommentDialect() {     return new ConditionalCommentsDialect(); } 

Spring Boot, in the ThymeleafAutoConfiguration class, will automatically add any Beans that implement the IDialect interface.

like image 180
xdhmoore Avatar answered Sep 19 '22 12:09

xdhmoore