Timeleaf reads property inside replacement

I have this piece of code where tdk is a shared variable that I defined in the SpringBoot application.properties file called server.contextPath

I would like to know if there is a way to replace it with

 <head th:replace="tdk/common/header :: common-header" /> 

something like

 <head th:replace="@environment.get('server.contextPath')/common/header :: common-header" /> 

I use

 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>1.5.3.RELEASE</version> </dependency> 

I also tried:

 <head th:replace="~{${@environment.getProperty('serverContextPath') + '/common/header'} :: common-header}" /> 

with this result:

 org.thymeleaf.exceptions.TemplateInputException: Error resolving template "~{${@environment.getProperty('serverContextPath') + '/common/header'}", template might not exist or might not be accessible by any of the configured Template Resolvers (/tdk/registration/signup:6) 
+8
spring-boot thymeleaf
source share
1 answer

If you are using thymeleaf 3, you can accomplish this with fragment expressions . I think it should look something like this:

 <head th:replace="~{${@environment.getProperty('myPropertyName') + '/common/header'} :: common-header}" /> 
+2
source share

All Articles