Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#1650 closed enhancement (fixed)

[patch] Allow templates to extend from parents in local context

Reported by: clelland@… Owned by: adrian
Component: Template system Version: magic-removal
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

It can be useful for templates to extend a base template which does not necessarily exist on the filesystem -- for example, the base template may be stored in the database, or it may be generated at runtime.

This patch allows a template object in the curent context to be used as a base template for inheritance.

Example:

>>> from django.template import Context, Template, loader
>>> child = Template("{% extends parent %}{% block one %}Hello, {{ name }}{% endblock %}")
>>> parent = Template("<h1>{% block one %}Name{% endblock %}</h1>")
>>> child.render(Context({'name': 'World', 'parent': parent}))

returns "<h1>Hello, World</h1>"

Attachments (1)

template-loader.diff (3.1 KB) - added by clelland@… 9 years ago.

Download all attachments as: .zip

Change History (2)

Changed 9 years ago by clelland@…

comment:1 Changed 9 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [3465].

Note: See TracTickets for help on using tickets.
Back to Top