Django

Code

Ticket #1650 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

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

Reported by: clelland@gmail.com Assigned to: adrian
Milestone: Component: Template system
Version: magic-removal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

template-loader.diff (3.1 kB) - added by clelland@gmail.com on 04/17/06 05:52:01.

Change History

04/17/06 05:52:01 changed by clelland@gmail.com

  • attachment template-loader.diff added.

07/27/06 18:26:49 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [3465].


Add/Change #1650 ([patch] Allow templates to extend from parents in local context)




Change Properties
Action