-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add ability to render thymeleaf fragments #678
Add ability to render thymeleaf fragments #678
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am interested in improving how to integrate better HTMX with Micronaut Views. And the same for Thymleaf. I use Thymleaf in my pet projects.
However, I am not sure I understand the benefit this PR adds. Currently, I can already render a thymleaf fragment in Micronaut Views template, I do something like:
<div th:replace="~{_piecharts :: piecharts(${charts.get(0)})}"></div>
and _piechart.html
fragment is something like:
<th:block th:fragment="piechart(chart)" xmlns:th="http://www.thymeleaf.org">
<div class="chart">
...
</th:block>
@sdelamo You are correct in that you already can render a fragment within a template. What does not work however, is to render only a fragment. For example, these code examples do not currently work:
This PR adds support for this by parsing the view name and get its fragment selector before sending it to the renderer. I'm also interested in improving integration with htmx. If this PR gets approved, I might give it a shot. |
Sorry for the delay. I set aside to work on this again. @johannesg this works: to answer a fragment: The issue you are trying to address it to support the |
@sdelamo Thank you for looking at this. It's true, if you have one file per fragment, then your example works. However, if you organize multiple fragments in one file, like this:
And you only want to render "fragment1", then you would need the |
@johannesg can you sign the CLA again?. Sorry for the inconvenience. |
Done |
This PR adds the ability to return a thymeleaf fragment in a view instead of the whole template. Very useful for tools like htmx.org.
This code takes inspiration from the thymeleaf spring integration, found here