Skip to content

Commit 3b858ed

Browse files
BigMichi1philwebb
authored andcommitted
Auto-configure for Thymeleaf conditionalcomments
Add auto-configuration for thymeleaf-extras-conditionalcomments which allows parsing of conditional comments for IE. Example: <!--[if lt IE 8]> <link rel="stylesheet" th:href="@{/styleIE.css}" type="text/css"/> <![endif]--> Without this dialect all Thymeleaf attributes are ignored inside the comment. Fixes gh-2113
1 parent 5c27cba commit 3b858ed

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

spring-boot-autoconfigure/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@
375375
<artifactId>thymeleaf-extras-data-attribute</artifactId>
376376
<optional>true</optional>
377377
</dependency>
378+
<dependency>
379+
<groupId>org.thymeleaf.extras</groupId>
380+
<artifactId>thymeleaf-extras-conditionalcomments</artifactId>
381+
<optional>true</optional>
382+
</dependency>
378383
<dependency>
379384
<groupId>org.thymeleaf.extras</groupId>
380385
<artifactId>thymeleaf-extras-springsecurity3</artifactId>

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.springframework.core.io.ResourceLoader;
4242
import org.springframework.util.Assert;
4343
import org.thymeleaf.dialect.IDialect;
44+
import org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect;
4445
import org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect;
4546
import org.thymeleaf.spring4.SpringTemplateEngine;
4647
import org.thymeleaf.spring4.resourceresolver.SpringResourceResourceResolver;
@@ -163,6 +164,18 @@ public SpringSecurityDialect securityDialect() {
163164

164165
}
165166

167+
@Configuration
168+
@ConditionalOnClass(ConditionalCommentsDialect.class)
169+
protected static class ThymeleafConditionalCommentsDialectConfiguration {
170+
171+
@Bean
172+
@ConditionalOnMissingBean
173+
public ConditionalCommentsDialect conditionalCommentsDialect() {
174+
return new ConditionalCommentsDialect();
175+
}
176+
177+
}
178+
166179
@Configuration
167180
@ConditionalOnClass({ Servlet.class })
168181
@ConditionalOnWebApplication

spring-boot-dependencies/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
<sun-mail.version>${javax-mail.version}</sun-mail.version>
128128
<thymeleaf.version>2.1.3.RELEASE</thymeleaf.version>
129129
<thymeleaf-extras-springsecurity3.version>2.1.1.RELEASE</thymeleaf-extras-springsecurity3.version>
130+
<thymeleaf-extras-conditionalcomments.version>2.1.1.RELEASE</thymeleaf-extras-conditionalcomments.version>
130131
<thymeleaf-layout-dialect.version>1.2.7</thymeleaf-layout-dialect.version>
131132
<thymeleaf-extras-data-attribute.version>1.3</thymeleaf-extras-data-attribute.version>
132133
<tomcat.version>8.0.15</tomcat.version>
@@ -1404,6 +1405,11 @@
14041405
<artifactId>thymeleaf-spring4</artifactId>
14051406
<version>${thymeleaf.version}</version>
14061407
</dependency>
1408+
<dependency>
1409+
<groupId>org.thymeleaf.extras</groupId>
1410+
<artifactId>thymeleaf-extras-conditionalcomments</artifactId>
1411+
<version>${thymeleaf-extras-conditionalcomments.version}</version>
1412+
</dependency>
14071413
<dependency>
14081414
<groupId>org.thymeleaf.extras</groupId>
14091415
<artifactId>thymeleaf-extras-springsecurity3</artifactId>

0 commit comments

Comments
 (0)