gin
gin copied to clipboard
add partial rendering to context.HTML() or add context.HTMLBlock()
Description
context.HTML() has the signature (code int, name string, obj any)
However, with the rise of htmx, partial rendering is desirable. With the current signature of context.HTML this isn't possible.
In an example repo at https://github.com/bugbytes-io/htmx-go-demo/tree/master you can see the index.html having a block and how it's rendered. https://github.com/bugbytes-io/htmx-go-demo/blob/1df93f925d27a5d6df862f7a498417fecefa96be/main.go#L39C1-L39C1
So with
tmpl := template.Must(template.ParseFiles("index.html"))
tmpl.ExecuteTemplate(w, "film-list-element", Film{Title: title, Director: director})
the block "film-list-element" is rendered with this Film object, and nothing else.
context.HTML is only able to render the whole index.html file, not just the defined block.
Solution
Either extend context.HTML or add a new function to context. Maybe context.HTMLBlock or context.Partial?