sponsfreixes / jinja2-fragments

Render Jinja2 template block as HTML page fragments on Python web frameworks.
MIT License
245 stars 13 forks source link

Support rendering multiple blocks #34

Closed rHuggler closed 2 months ago

rHuggler commented 3 months ago

Add support for rendering multiple blocks at once.

First of all I'm new to HTMX, if this should be accomplished in other ways you can just point me towards the right direction and close this.

I was following ThePrimeagen's introduction to HTMX on FrontEnd Masters but using Python + FastAPI instead of Golang + Echo and I noticed this pattern he used for rendering the form PLUS an out-of-bound element to update the contacts.

c.Render(200, "form", newFormData())
return c.Render(200, "oob-contact", contact)

I tried searching how I could do that with my stack but found nothing, tried to do something similar by joining the resulting content but ended up with Content-Length header errors and I thought I could try to modify the library to allow something similar to this pattern. This is PR is what I've achieved and it can be used like this:

return templates.TemplateResponse(
    "index.html.jinja2", context, block_name_list=["form", "oob_contact"]
)

This is my first time contributing and I'll be happy to have any feedback :)

sponsfreixes commented 3 months ago

Hi @rHuggler, thank you very much for the PR! Just wanted to let you know that I have it on my radar, trying to find the time to properly go though it to give meaningful feedback.

flkc commented 2 months ago

Hello everyone,

I've made an integration for the Quart framework, complete with tests. I'll keep an eye on this pull request and submit another one afterwards.

Thank you for this fantastic package!

rHuggler commented 2 months ago

Added a test for the async function and discovered I messed up by nesting async functions.

But it works like a charm now!

sponsfreixes commented 2 months ago

Great! I'll merge in on the next days, plus I'll add some documentation about it. I'm starting to thing I might need some proper docs instead of cramming everything into the README,