J.F.
J.F.

Reputation: 15207

Is it possible update multiple templates from controller in Thymeleaf?

I am using Thymeleaf in a project.

The point is, when controller is called I want to return two templates, one containing the response and another one containing the new data to display. So, update two fragments.

Controller code is as follows:

@GetMapping("/...")
public String multiTemplate(...){
  // do things

  return "resultsTemplate :: fragment1" && return "responseTemplate :: fragment2" <---- how?

}

To be clearer, for example you have a list of objects and you can filter them. When you filter, your backend receives code 200 and the new list, so the front end will show "search successful" and will update the list.

Now with two different calls I can return one thing or another, but I want to know if it is possible to return two templates at the same time.

Thanks.

Upvotes: 0

Views: 715

Answers (1)

Krishan Mohan
Krishan Mohan

Reputation: 26

You should use this one return top fragment from the controller

<div th:fragment=top>
  <div th:fragment=first>
  </div>
  <div th:fragment=second>
  </div>
</div>

Upvotes: 1

Related Questions