Opened 7 years ago

Last modified 14 months 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@… 7 years ago.
Initial version with with docs
inclusion_tag_using_template2.diff (4.6 KB) - added by exogen@… 7 years ago.
Fixed typos in docs
inclusion_tag_using_template3.diff (4.7 KB) - added by exogen@… 7 years ago.
Fixed diff whitespace, docs typos
inclusion_tag_using_template4.diff (5.0 KB) - added by exogen@… 7 years ago.
allow_template_override is now allow_override

Download all attachments as: .zip

Change History (16)

Changed 7 years ago by exogen@…

Initial version with with docs

Changed 7 years ago by exogen@…

Fixed typos in docs

comment:1 Changed 7 years ago by anonymous

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Changed 7 years ago by exogen@…

Fixed diff whitespace, docs typos

Changed 7 years ago by exogen@…

allow_template_override is now allow_override

comment:2 Changed 7 years ago by anonymous

  • Cc edcrypt@… added

comment:3 Changed 7 years ago by andybak

  • Cc andy@… added

comment:4 Changed 7 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:5 Changed 7 years ago by jacob

  • Triage Stage changed from Unreviewed to Design decision needed

comment:6 Changed 6 years ago by andrewbadr

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 6 years ago by ramusus

  • Cc ramusus@… added

comment:8 Changed 4 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:9 Changed 4 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:10 Changed 4 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:11 Changed 2 years ago by jacob

  • Triage Stage changed from Design decision needed to Accepted

comment:12 Changed 14 months ago by timo

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