How do I add a thymeleaf dialect to spring boot?

xdhmoore picture xdhmoore · May 8, 2014 · Viewed 18.8k times · Source

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?

Answer

xdhmoore picture xdhmoore · May 8, 2014

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.