[Django] #36130: Add inclusion support for simple block tags

7 views
Skip to first unread message

Django

unread,
Jan 23, 2025, 12:28:23 PM1/23/25
to django-...@googlegroups.com
#36130: Add inclusion support for simple block tags
-----------------------------+-------------------------------------------
Reporter: Jake Howard | Type: New feature
Status: new | Component: Template system
Version: | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-------------------------------------------
Django's template system allows creating tags which include other
templates:

{{{#!python
@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.

{{{#!python
@register.inclusion_block_tag("results.html")
def show_results(content, poll):
choices = poll.choice_set.all()
return {"content": content, "choices": choices}
}}}

{{{#!django
{% 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36130>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 23, 2025, 12:29:23 PM1/23/25
to django-...@googlegroups.com
#36130: Add inclusion support for simple block tags
---------------------------------+--------------------------------------
Reporter: Jake Howard | Owner: (none)
Type: New feature | Status: new
Component: Template system | Version:
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by Jake Howard):

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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36130#comment:1>

Django

unread,
Jan 24, 2025, 5:37:13 AM1/24/25
to django-...@googlegroups.com
#36130: Add inclusion support for simple block tags
---------------------------------+--------------------------------------
Reporter: Jake Howard | Owner: (none)
Type: New feature | Status: closed
Component: Template system | Version:
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Sarah Boyce):

* resolution: => wontfix
* status: new => closed

Comment:

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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36130#comment:2>

Django

unread,
Apr 12, 2025, 2:28:53 AM4/12/25
to django-...@googlegroups.com
#36130: Add inclusion support for simple block tags
---------------------------------+--------------------------------------
Reporter: Jake Howard | Owner: (none)
Type: New feature | Status: closed
Component: Template system | Version:
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Sébastien Corbin):

* cc: Sébastien Corbin (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/36130#comment:3>
Reply all
Reply to author
Forward
0 new messages