Django

Code

Ticket #9093 (new)

Opened 2 years ago

Last modified 8 months ago

Extend inclusion tag syntax to allow custom templates

Reported by: exogen@gmail.com Assigned to: nobody
Milestone: Component: Template system
Version: 1.0 Keywords: inclusion
Cc: edcrypt@gmail.com, andy@andybak.net, ramusus@gmail.com Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

inclusion_tag_using_template.diff (5.1 kB) - added by exogen@gmail.com on 09/16/08 02:30:54.
Initial version with with docs
inclusion_tag_using_template2.diff (4.6 kB) - added by exogen@gmail.com on 09/16/08 02:43:06.
Fixed typos in docs
inclusion_tag_using_template3.diff (4.7 kB) - added by exogen@gmail.com on 09/16/08 03:01:00.
Fixed diff whitespace, docs typos
inclusion_tag_using_template4.diff (5.0 kB) - added by exogen@gmail.com on 09/16/08 12:01:38.
allow_template_override is now allow_override

Change History

09/16/08 02:30:54 changed by exogen@gmail.com

  • attachment inclusion_tag_using_template.diff added.

Initial version with with docs

09/16/08 02:43:06 changed by exogen@gmail.com

  • attachment inclusion_tag_using_template2.diff added.

Fixed typos in docs

09/16/08 02:43:21 changed by anonymous

  • needs_better_patch changed.
  • has_patch set to 1.
  • needs_tests changed.
  • needs_docs changed.

09/16/08 03:01:00 changed by exogen@gmail.com

  • attachment inclusion_tag_using_template3.diff added.

Fixed diff whitespace, docs typos

09/16/08 12:01:38 changed by exogen@gmail.com

  • attachment inclusion_tag_using_template4.diff added.

allow_template_override is now allow_override

09/21/08 16:08:08 changed by anonymous

  • cc set to edcrypt@gmail.com.

09/29/08 09:34:16 changed by andybak

  • cc changed from edcrypt@gmail.com to edcrypt@gmail.com, andy@andybak.net.

02/25/09 13:51:44 changed by

  • milestone deleted.

Milestone post-1.0 deleted

02/25/09 22:08:34 changed by jacob

  • stage changed from Unreviewed to Design decision needed.

05/08/09 16:59:35 changed 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.

07/14/09 18:54:51 changed by ramusus

  • cc changed from edcrypt@gmail.com, andy@andybak.net to edcrypt@gmail.com, andy@andybak.net, ramusus@gmail.com.

Add/Change #9093 (Extend inclusion tag syntax to allow custom templates)




Change Properties
Action