Opened 19 years ago

Closed 18 years ago

Last modified 18 years ago

#1650 closed enhancement (fixed)

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

Reported by: clelland@… Owned by: Adrian Holovaty
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: no UI/UX: no

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@… 19 years ago.

Download all attachments as: .zip

Change History (2)

by clelland@…, 19 years ago

Attachment: template-loader.diff added

comment:1 by Jacob, 18 years ago

Resolution: fixed
Status: newclosed

Fixed in [3465].

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