Opened 4 weeks ago
Closed 4 weeks ago
#36130 closed New feature (wontfix)
Add inclusion support for simple block tags
Reported by: | Jake Howard | Owned by: | |
---|---|---|---|
Component: | Template system | Version: | |
Severity: | Normal | Keywords: | |
Cc: | Jake Howard | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Django's template system allows creating tags which include other templates:
@register.inclusion_tag("results.html") def show_results(poll): choices = poll.choice_set.all() return {"choices": choices}
However, with the addition of simple_block_tag
in #35535, it would be nice to combine the 2 into a inclusion_block_tag
. This creates a form of reusable component for Django template, combining context transformation, rendering and internal content. There are a number of libraries in the Django ecosystem which achieve this (eg slippers
), so there's clearly an appetite for this functionality.
@register.inclusion_block_tag("results.html") def show_results(content, poll): choices = poll.choice_set.all() return {"content": content, "choices": choices}
{% show_results poll %} This content gets captured too {% endmysimpletag %}
The API matches the existing inclusion_tag
, but with an additional required content
argument containing the (rendered) template content.
Change History (2)
comment:1 by , 4 weeks ago
comment:2 by , 4 weeks ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Some related discussions:
- https://github.com/django/django/pull/18343#discussion_r1697263460
- https://forum.djangoproject.com/t/feature-proposal-simple-block-tag/32229/9
I think we need more community feedback before this can be accepted.
I personally think it's also good to wait after the 5.2 final release to see how folks use simple_block_tag
and if we get any feedback from that.
An open question I have about this approach: Should
content
be implicitly passed through to the template, or require passing in via the context? It feels like a case of "explicit > implicit", however it's also a fairly easy foot-gun and confusion for developers.