Qute: Provide a clean way to return multiple fragments in one response (Htmx OOB Swap)
See original GitHub issueDescription
HTMX allow to do Out of band swapping of content: https://htmx.org/attributes/hx-swap-oob/
This means that the response contains multiple fragments of the view to be updated.
Example:
When you click on the note, you need to update both the editor and the list of note.
Implementation ideas
I currently use this as a workaround: oob.html
{#for i in items}
{i.raw}
{/for}
public static native TemplateInstance oob(Uni<String>... items);
...
@Path("/note/{id}")
public TemplateInstance editNote(@PathParam("id") Long id) {
final Note note = Note.findById(id);
if(note == null) {
notes(null);
return null;
}
if (isHxRequest()) {
return Templates.oob(
Templates.notes$noteList(Note.listAllSortedByLastUpdated(), id).createUni(),
Templates.notes$noteForm(note).createUni()
);
}
return Templates.notes(Note.listAllSortedByLastUpdated(), id, note);
}
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
multi-swap extension - </> htmx
This extension allows you to swap multiple elements marked with the id attribute from the HTML response. You can also choose for each...
Read more >Specify multiple targets to swap #44 - bigskysoftware/htmx
I understand how the oob feature lets me return multiple containers ... such that it only returns fragments in response to an htmx...
Read more >Can hx-select-oob update several targets? - Stack Overflow
If your goal is to return html content and copy the same content to multiple targets - you simply use class selector instead...
Read more >Out-of-band swaps with HTMX - .NET Guide - JetBrains
HTMX can process responses before placing them into our target element. Therefore, we only need to add the hx-swap-oob attribute along with ...
Read more >Django and HTMX #17 - Updating Other Content - YouTube
In this video, learn how to update non-target elements using two different HTMX mechanisms: 1. Out-of-band swaps : with the hx- swap -...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This seems like a very good solution, I’ll add it to the future Renarde HxController for now.
https://github.com/ia3andy/renotes/blob/main/src/main/java/rest/HxController.java#L55