Closed scratchmex closed 1 year ago
To render a block manually:
t = env.get_template("index.html")
"".join(t.blocks["content"](t.new_context(magic_number=42)))
To render a macro manually:
t.module.content(magic_number=42)
I don't think we need to do anything else. jinja2-fragments looks great, I think there's another similar extension as well.
Given the following template
If you want to render only the
content
block, do:Which is basically something like this: https://github.com/sponsfreixes/jinja2-fragments
This is very useful with frameworks like htmx because you rerender a specific part of the template without having to split into multiple files and having a partials-mess
Another reference of why this might be useful is this essay Template Fragments - HTMX
I am open to submit a PR