﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33819	Add shortcut for rendering multiple templates.	Thomas De Bonnet	Thomas De Bonnet	"After extensive use of HTMX and Django I found the need to have a multiple render template system. This is because i'm creating more and more partials (small template with a specific purpose).

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,
)

}}}






"	New feature	closed	Template system	4.0	Normal	wontfix	HTMX, render, template	Adam Johnson	Unreviewed	0	0	0	0	0	0
