What is good about this new feature is that you can string together
multiple templates, provide one context, and render it as one template.
This is particularly handy when using HTMX, because you can string
together multiple small templates, and HTMX will pickup on them and
replace the corresponding HTML (this is done with hx-swap-oob)
This makes the backend very flexible and customizable.
The code would live in django.shortcuts and would look like this:
{{{
def render_multiple(request, template_names, context):
rendered_html = ""
for template_name in template_names:
rendered_html += render_to_string(
template_name, context=context, request=request
)
return HttpResponse(rendered_html)
}}}
It basically loops over render_to_string, and returns a rendered template.
In the view it could be used like this:
{{{
return render(
request,
["foo.html", "bar.html"], # note the list
context,
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33819>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => Thomas De Bonnet
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/33819#comment:1>