How can I get unescaped JavaScript inlining output with Thymeleaf 3.0.x? Escaped inlining works just fine. Example:
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring3</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
servelet:
model.addAttribute("test", "testing...");
html template:
<script th:inline="javascript">
/*<![CDATA[*/
[[${test}]]
[(${test})]
/*]]>*/
</script>
generated output:
<script>
/*<![CDATA[*/
'testing...'
[(${test})]
/*]]>*/
</script>
So, escaped expression [[ ]]
works, but unescaped expression [( )]
doesn't. I have a need to generate js conditionally, and there's no "easy" workaround, so this would've been very helpful. Has anyone been able to get this to work? Any help much appreciated!
I finally got it to work with Spring Boot with the following four dependencies, all four being required (I'm using the latest versions currently available):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>2.1.2</version>
</dependency>
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With