Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Support rendering of partial thymeleaf fragments #66

Open
v79 opened this issue Aug 18, 2017 · 3 comments
Open

Feature request: Support rendering of partial thymeleaf fragments #66

v79 opened this issue Aug 18, 2017 · 3 comments

Comments

@v79
Copy link

v79 commented Aug 18, 2017

In Spring/Thymeleaf, it is possible for a controller to ask Thymeleaf to render part of a page declared as a th:fragment, e.g.:

@RequestMapping(value = "/guests", method = RequestMethod.GET)
public String showGuestList(Model model) {
    model.addAttribute("guests", hotelService.getGuestsList());
    
    return "results :: resultsList";
}

Where resultsList is defined inside a bigger Thymeleaf template as <div th:fragment="resultsList" th:unless="${#lists.isEmpty(guests)}" class="results-block">...</div>.

(As described here and elsewhere).

What would it take add the same functionality in spark? I'm willing to try it myself but don't know where to start.

When writing AJAX-heavy web pages I'm having to move all my th:fragments into separate HTML files, which breaks one of the benefits of using Thymeleaf and is a lot of effort.

@tipsy
Copy link
Collaborator

tipsy commented Aug 19, 2017

What would it take add the same functionality in spark? I'm willing to try it myself but don't know where to start.

If this is a thymeleaf-feature you just need to find a way of calling it. You could add an overload, like ThymeleafEngine.render(model, template, fragment)? If it's a Spring feature, you'll have to copy or re-implement the functionality.

@v79
Copy link
Author

v79 commented Aug 19, 2017

Amazing timing @tipsy - I had a flash of inspiration this morning and got it working with the overload mechanism you suggested. Just 5 minutes before your comment!

@tipsy
Copy link
Collaborator

tipsy commented Aug 19, 2017

Great! If you make a PR I'll merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants