Opened 8 years ago

Last modified 2 years ago

#9093 new New feature

Extend inclusion tag syntax to allow custom templates

Reported by: exogen@… Owned by: nobody
Component: Template system Version: 1.0
Severity: Normal Keywords: inclusion
Cc: edcrypt@…, andy@…, ramusus@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Currently, inclusion tags are not very reusable since they are bound to a template at registration time. For example, the only way to customize Djagno admin's change_list_results.html template is to ensure your template of the same name is found first. I propose extending the inclusion tag syntax so that all inclusion tags can be called like so:

{% show_results poll using "custom/results.html" %}

If the "using ..." part is omitted, the template specified during registration will be used. (The keyword decided upon, 'using' in this case, is not important.)

The only problem: this could break existing apps that use the keyword ('using' in this case) as a variable name. But we can make this behavior well-defined.

Attachments (4)

inclusion_tag_using_template.diff (5.1 KB) - added by exogen@… 8 years ago.
Initial version with with docs
inclusion_tag_using_template2.diff (4.6 KB) - added by exogen@… 8 years ago.
Fixed typos in docs
inclusion_tag_using_template3.diff (4.7 KB) - added by exogen@… 8 years ago.
Fixed diff whitespace, docs typos
inclusion_tag_using_template4.diff (5.0 KB) - added by exogen@… 8 years ago.
allow_template_override is now allow_override

Download all attachments as: .zip

Change History (16)

Changed 8 years ago by exogen@…

Initial version with with docs

Changed 8 years ago by exogen@…

Fixed typos in docs

comment:1 Changed 8 years ago by anonymous

Has patch: set

Changed 8 years ago by exogen@…

Fixed diff whitespace, docs typos

Changed 8 years ago by exogen@…

allow_template_override is now allow_override

comment:2 Changed 8 years ago by anonymous

Cc: edcrypt@… added

comment:3 Changed 8 years ago by Andy Baker

Cc: andy@… added

comment:4 Changed 8 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:5 Changed 8 years ago by Jacob

Triage Stage: UnreviewedDesign decision needed

comment:6 Changed 8 years ago by Andrew Badr

Even if you're willing to write multiple inclusion tags for some finite number of templates that take the same context, you have to write a wrapper around the context function. (Django won't let you use the same function for multiple inclusion tags.) One possible workaround might be to do {% with inclusion_template as 'whatever'%}{% show_result %}{% endwith %} and show_result would render a template that includes the inclusion_template that it gets from the context.

comment:7 Changed 7 years ago by ramusus

Cc: ramusus@… added

comment:8 Changed 6 years ago by Luke Plant

Severity: Normal
Type: New feature

comment:9 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:10 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:11 Changed 4 years ago by Jacob

Triage Stage: Design decision neededAccepted

comment:12 Changed 2 years ago by Tim Graham

Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top