Is it possible to create a dynamic replace in Thymeleaf?
I have the following controller:
@Controller
public class LoginController {
@RequestMapping
I believe the appropriate method to manage this behavior in thymeleaf is to use layout:fragment
tags. Please correct me if I'm wrong. Here is a simple example of my layout page, and the login page which is 'dynamically' loaded:
layout.html
Layout
Then, when login gets loaded, it replaces the th:fragment
div with the associated div in the html view which matches the string returned by the controller method, in this case login.html:
Login
Now, if you want to load another fragment conditionally, the approach I take is to add replace tags with th:if cases. Here's an example of a Form that displays different questions based on an attribute of the current user:
Then the associated div gets loaded from the file custom-questions.html:
//stuff
//stuff