Simply add this class which allows to set global variables for views:
@ControllerAdvice
public class BuildPropertiesController {
@Autowired
private Environment env;
@ModelAttribute("isProd")
public boolean isProd() {
return Arrays.asList(env.getActiveProfiles()).contains("production");
}
}
And then use ${isProd}
variable in your thymeleaf file:
<div th:if="${isProd}">
This is the production profile
</div>
Or you can set active profile name as a global variable:
@ControllerAdvice
public class BuildPropertiesController {
@Autowired
private Environment env;
@ModelAttribute("profile")
public String activeProfile() {
return env.getActiveProfiles()[0];
}
}
And then use ${profile}
variable in your thymeleaf file (if you have one active profile):
<div>
This is the <span th:text="${profile}"></span> profile
</div>