#33819: Add multiple template render support
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  nobody
  thomasdebonnet                     |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Template   |        Version:  4.0
  system                             |       Keywords:  HTMX, render,
               Severity:  Normal     |  template
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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,
 )

 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33819>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070181ba0556ae-14df33b6-4d37-4bb9-a01a-9c4b94794610-000000%40eu-central-1.amazonses.com.

Reply via email to