How to set variables in a thymeleaf fragment?

Viewed 25255

I understand Thymeleaf is made for rendering the views however, I just wanted to know if there is any way to set a variable may be in request scope in a Thymeleaf fragment?

I have a very large conditional expression that I have to repeat a lot of times across the application so it will be really helpful if I can set a variable in main layout then reuse it in all other child fragments.

I am aware of using a Spring interceptor and setting the variable in model but I prefer not to.

Please advise.

Thanks

Prash

4 Answers
<div th:include="'path/your/file/' + ${variable}"></div>

The code above can use variables that you can choose to build the file path

Related