[Django] #35535: Simple block tag

5 views
Skip to first unread message

Django

unread,
Jun 19, 2024, 3:44:13 AMJun 19
to django-...@googlegroups.com
#35535: Simple block tag
-------------------------------------------+-----------------------------
Reporter: Jake Howard | Owner: Jake Howard
Type: New feature | Status: assigned
Component: Template system | Version: 5.0
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 custom tags, but they don't allow
taking content:

{{{#!django
{% mysimpletag foo="bar" %}
}}}

However there are plenty of use-cases where it'd be useful to also collect
content along with the tag, turning it into a "block" tag:

{{{#!django
{% mysimpletag foo="bar" %}
This content gets captured too
{% endmysimpletag %}
}}}

This currently requires using complex internals of the template system
(some documented, some not) to achieve. The
[https://github.com/django/django/blob/main/django/templatetags/cache.py
cache tag] is a good example of this kind of "simple" block, which
requires some parser internals.

I propose adding a `@register.simple_block` method to allow easy
registering of custom block tags. The API would be similar to
`simple_tag`, however with a required `content` argument containing the
(rendered) template content:

{{{#!python
@register.simple_block(takes_context=True)
def mysimpletag(context: Context, content: str, foo: str) -> str:
return f"foo = {foo}"
}}}

(Types added for reference)

I have a working demo of this I can push up.
--
Ticket URL: <https://code.djangoproject.com/ticket/35535>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 19, 2024, 5:30:43 AMJun 19
to django-...@googlegroups.com
#35535: Simple block tag
---------------------------------+---------------------------------------
Reporter: Jake Howard | Owner: Jake Howard
Type: New feature | Status: closed
Component: Template system | Version: 5.0
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: assigned => closed

Comment:

Hi Jake👋 thank you for raising this, I can see why this could be useful.

For a feature request to be accepted, we want to see some discussion on
the [https://forum.djangoproject.com/c/internals/5 forum] first to
confirm/validate the feature with the community and get some feedback.
I'll close the ticket for now, but if there is a community agreement for
this, you are welcome to come back linking the forum topic, so we can then
re-open it.
For more details, please see
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features the documented guidelines for requesting
features] 👍
--
Ticket URL: <https://code.djangoproject.com/ticket/35535#comment:1>

Django

unread,
Jun 19, 2024, 5:55:58 AMJun 19
to django-...@googlegroups.com
#35535: Simple block tag
---------------------------------+---------------------------------------
Reporter: Jake Howard | Owner: Jake Howard
Type: New feature | Status: closed
Component: Template system | Version: 5.0
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
---------------------------------+---------------------------------------
Comment (by Jake Howard):

For now, I've now raised this on the forum:
https://forum.djangoproject.com/t/feature-proposal-simple-block-tag/32229.
Will collect feedback, and then return!
--
Ticket URL: <https://code.djangoproject.com/ticket/35535#comment:2>

Django

unread,
Jun 19, 2024, 6:19:42 AMJun 19
to django-...@googlegroups.com
#35535: Simple block tag
---------------------------------+---------------------------------------
Reporter: Jake Howard | Owner: Jake Howard
Type: New feature | Status: closed
Component: Template system | Version: 5.0
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 Carlton Gibson):

* cc: Carlton Gibson (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/35535#comment:3>

Django

unread,
10:51 AM (8 hours ago) 10:51 AM
to django-...@googlegroups.com
#35535: Simple block tag
---------------------------------+---------------------------------------
Reporter: Jake Howard | Owner: Jake Howard
Type: New feature | Status: new
Component: Template system | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+---------------------------------------
Changes (by Jake Howard):

* has_patch: 0 => 1
* resolution: wontfix =>
* status: closed => new

Comment:

Following a few conversations on the forum thread, I've opened a [PR
https://github.com/django/django/pull/18343].
--
Ticket URL: <https://code.djangoproject.com/ticket/35535#comment:4>

Django

unread,
3:56 PM (2 hours ago) 3:56 PM
to django-...@googlegroups.com
#35535: Simple block tag
---------------------------------+---------------------------------------
Reporter: Jake Howard | Owner: Jake Howard
Type: New feature | Status: new
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+---------------------------------------
Changes (by Natalia Bidart):

* stage: Unreviewed => Accepted
* version: 5.0 => dev

Comment:

Thank you Jake for following up on this. I think the forum post shows
enough agreement, and I personally also think this is a useful adding. I
also agree with related comments from #6378, specifically:

> I do think there are cases where the "capture" model is the appropriate
one, and it ought to be built-in.

I considered reopening #6378 and closing this as a dupe, but I decided not
to because the older ticket is a bit confusing in how the problem is
described because there is a mix of requirements which some were solved by
#18651.
--
Ticket URL: <https://code.djangoproject.com/ticket/35535#comment:5>
Reply all
Reply to author
Forward
0 new messages