Extending templates dynamically

25 views
Skip to first unread message

Christophe Pettus

unread,
May 6, 2011, 3:25:16 PM5/6/11
to django-d...@googlegroups.com
Having had to do some PHP programming for the first time in a long time, I discovered that the Smarty template language has taken Django's template inheritance mechanism and adopted it wholesale in version 3:

http://www.smarty.net/docs/en/advanced.features.template.inheritance.tpl

Steal from the best! :) One additional feature that they added was a dynamic way of doing {{ extends }}. Rather than specifying the tag in the template source, the inheritance path can be specified directly in the render-equivalent call. This has proven to be quite useful for those times that an inner template is used in multiple wrapper contexts. Is this something that might be worth investigating in Django? Looking at the Django source, the implementation seems quite straight-forward.

--
-- Christophe Pettus
x...@thebuild.com

Marty Alchin

unread,
May 6, 2011, 3:32:39 PM5/6/11
to django-d...@googlegroups.com
On Fri, May 6, 2011 at 12:25 PM, Christophe Pettus <x...@thebuild.com> wrote:
> Steal from the best! :)  One additional feature that they added was a dynamic way of doing {{ extends }}.  Rather than specifying the tag in the template source, the inheritance path can be specified directly in the render-equivalent call.  This has proven to be quite useful for those times that an inner template is used in multiple wrapper contexts.  Is this something that might be worth investigating in Django?  Looking at the Django source, the implementation seems quite straight-forward.

Does the current behavior of {% extends %} not do what you want?

http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#extends

In particular, note that you can supply any template variable as the
argument to {% extends %} in order to dynamically inherit from
whatever template your view decides is appropriate. That said, if you
have questions about using {% extends %} in this way, it's probably
best to take it to django-users instead.

-Marty

Reply all
Reply to author
Forward
0 new messages