I have this piece of code, where tdk is a common variable I have defined in the SpringBoot file application.properties
named server.contextPath
I would like to know if there is a way to replace it for
<head th:replace="tdk/common/header :: common-header" />
something like
<head th:replace="@environment.get('server.contextPath')/common/header :: common-header" />
I am using
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
I've 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)
#{} is used for message (i18n) expressions. Used to retrieve locale-specific messages from external sources.
In Thymeleaf, these model attributes (or context variables in Thymeleaf jargon) can be accessed with the following syntax: ${attributeName} , where attributeName in our case is messages . This is a Spring EL expression.
Thymeleaf is a great templating engine which replaces JSP, and you can easily use it in any Spring MVC or Spring Boot application. Unlike JSP it's a pleasure to use.
If you are using thymeleaf 3, you can accomplish this using fragment expressions. I think it should look something like this:
<head th:replace="~{${@environment.getProperty('myPropertyName') + '/common/header'} :: common-header}" />
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