[Django] #35636: differentiate placeholder and content provider blocks

18 views
Skip to first unread message

Django

unread,
Jul 26, 2024, 10:59:00 PM7/26/24
to django-...@googlegroups.com
#35636: differentiate placeholder and content provider blocks
-------------------------------------+-------------------------------------
Reporter: langit | Type: New
| feature
Status: new | Component: Template
| system
Version: 5.0 | Severity: Normal
Keywords: template block | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
The block is a core feature in the template system. Currently, the syntax
provides no explicit grammar to differentiate between a placeholder block
and a content provider block. In this ticket, an optional and fully
backward compatible syntax is proposed to mark a block as a content
provider. This new syntax enhances readability, and imposes little effort
to implement, and opens the door to allow multiple occurrences of the same
block in a single template being given different contents on different
conditions (this feature has been requested many times over the years).

Here is the proposed syntax illustrated with an example:


{{{
{% block usertools = %} here are my user tools. {% endblock %}
}}}


Note the equal sign in the end of the block opening mark, which is an
optional element added here to indicate that this is not a placeholder,
but a content provider for the block named 'usertools' defined somewhere
else.

If this syntax is implemented, the multiple occurrence of such content
providers in a single template file can be allowed in the future if deemed
desirable.
--
Ticket URL: <https://code.djangoproject.com/ticket/35636>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 26, 2024, 11:25:28 PM7/26/24
to django-...@googlegroups.com
#35636: differentiate placeholder and content provider blocks
---------------------------------+--------------------------------------
Reporter: Yingjie Lan | Owner: (none)
Type: New feature | Status: new
Component: Template system | Version: 5.0
Severity: Normal | Resolution:
Keywords: template block | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Description changed by Yingjie Lan:

Old description:

> The block is a core feature in the template system. Currently, the syntax
> provides no explicit grammar to differentiate between a placeholder block
> and a content provider block. In this ticket, an optional and fully
> backward compatible syntax is proposed to mark a block as a content
> provider. This new syntax enhances readability, and imposes little effort
> to implement, and opens the door to allow multiple occurrences of the
> same block in a single template being given different contents on
> different conditions (this feature has been requested many times over the
> years).
>
> Here is the proposed syntax illustrated with an example:
>

> {{{
> {% block usertools = %} here are my user tools. {% endblock %}
> }}}
>

> Note the equal sign in the end of the block opening mark, which is an
> optional element added here to indicate that this is not a placeholder,
> but a content provider for the block named 'usertools' defined somewhere
> else.
>
> If this syntax is implemented, the multiple occurrence of such content
> providers in a single template file can be allowed in the future if
> deemed desirable.

New description:

The block is a core feature in the template system. Currently, the syntax
provides no explicit grammar to differentiate between a placeholder block
and a content provider block. In this ticket, an optional and fully
backward compatible syntax is proposed to mark a block as a content
provider. This new syntax enhances readability, and imposes little effort
to implement, and opens the door to allow multiple occurrences of the same
block in a single template being given different contents on different
conditions (this feature has been requested many times over the years).

Here is the proposed syntax illustrated with an example:


{{{
{% block usertools = %} here are my user tools. {% endblock %}
}}}


Note the equal sign in the end of the block opening mark, which is an
optional element added here to indicate that this is not a placeholder,
but a content provider for the block named 'usertools' defined somewhere
else.

If this syntax is implemented (e.g. by using a boolean property of the
block object), the multiple occurrence of such content providers in a
single template file can be allowed in the future if deemed desirable.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/35636#comment:1>

Django

unread,
Jul 27, 2024, 1:33:59 AM7/27/24
to django-...@googlegroups.com
#35636: differentiate placeholder and content provider blocks
-------------------------------------+-------------------------------------
Reporter: Yingjie Lan | Owner:
| mhashirhassan22
Type: New feature | Status: assigned
Component: Template system | Version: 5.0
Severity: Normal | Resolution:
Keywords: template block | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by mhashirhassan22):

* owner: (none) => mhashirhassan22
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35636#comment:2>

Django

unread,
Jul 29, 2024, 3:22:55 AM7/29/24
to django-...@googlegroups.com
#35636: differentiate placeholder and content provider blocks
---------------------------------+-----------------------------------------
Reporter: Yingjie Lan | Owner: Hashir Hassan
Type: New feature | Status: closed
Component: Template system | Version: 5.0
Severity: Normal | Resolution: wontfix
Keywords: template block | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+-----------------------------------------
Changes (by Sarah Boyce):

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

Comment:

Hi Yingjie Lan, we recommend proposing new features on the
[https://forum.djangoproject.com/c/internals/5 Django Forum], where you'll
reach a wider audience and likely get extra feedback. You need to build
consensus that the community is in favor of this change.

Personally, I'm not in favor of doing this. I think the syntax is
confusing (looks like a typo) and the benefits are limited (you can
comment in a template if you want to add extra information).

But if you find there is a community agreement for this, you are welcome
to come back to the ticket and point to 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/35636#comment:3>

Django

unread,
Jul 29, 2024, 8:24:02 AM7/29/24
to django-...@googlegroups.com
#35636: differentiate placeholder and content provider blocks
---------------------------------+-----------------------------------------
Reporter: Yingjie Lan | Owner: Hashir Hassan
Type: New feature | Status: closed
Component: Template system | Version: 5.0
Severity: Normal | Resolution: wontfix
Keywords: template block | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+-----------------------------------------
Comment (by Yingjie Lan):

Hi Sarah Boyce, thanks a lot for your feedback! I have initiated a
[https://forum.djangoproject.com/t/differentiate-placeholder-and-content-
provider-blocks/33383 new topic] on the Django Forum. I am sorry that the
proposed syntax looks confusing to you, I should have explained it with
more clarity. The '=' sign is analogous to that in an assignment statement
in most programming languages, since a content provider block can be seen
as assigning a value or content to a block. Viewed in this way, hopefully
the syntax now looks more natural and meaningful. Besides enhancing
readability, I think there can be a lot of other benefits with this
syntax, such as having a block accumulate contents gradually based on
different conditions:

{{{
{% block usertools = %} my user tools {% endblock %}
{% if user.authorized %}
{% block usertools += %}, extra user tools {% endblock %}
{% endif %}
}}}

In this illustration, if user.authorized is False, then the block content
is simply 'my user tools', otherwise, it would be 'my user tools, extra
user tools'. This would make the block content specification more flexible
and convenient.
--
Ticket URL: <https://code.djangoproject.com/ticket/35636#comment:4>
Reply all
Reply to author
Forward
0 new messages