extends templates with the same name

290 views
Skip to first unread message

Alessandro Ronchi

unread,
Aug 6, 2010, 6:22:29 AM8/6/10
to django...@googlegroups.com
It's useful to have some templates with the same name of another one,
like you can do with YOURPROJECT/templates/admin/base_site.html that
override the base site django default.
but If I want to add a word in the title of my base_site.html I need
to copy the entire content of the base_site.html I am overriding, and
I cannot extend it to avoid that with am {% extend
"admin/templates/base_site.html" %}
or an {% extend super %}

I wrote a custom base_site.html with some common code for all my projects.
Now I need an app to add a single template_tag in a block. Is it
possible without copying ALL the previous base_site?
I cannot change the name of the parent template, or admin will not use
it when I don't install that app.

I moved
YOURPROJECT/templates/admin/base_site.html
to
YOURPROJECT/templates/admin/_base_site.html

and created an empty
YOURPROJECT/templates/admin/base_site.html
with only
{% extends "_base_site.html" %}

but it's not clean.

Is there any other cleaner way to do that?

--
Alessandro Ronchi
http://www.soasi.com

Hobby & Giochi
http://hobbygiochi.com
http://www.facebook.com/hobbygiochi

Reinout van Rees

unread,
Aug 6, 2010, 7:46:06 AM8/6/10
to django...@googlegroups.com
On 08/06/2010 12:22 PM, Alessandro Ronchi wrote:
> It's useful to have some templates with the same name of another one,
> like you can do with YOURPROJECT/templates/admin/base_site.html that
> override the base site django default.
> but If I want to add a word in the title of my base_site.html I need
> to copy the entire content of the base_site.html I am overriding, and
> I cannot extend it to avoid that with am {% extend
> "admin/templates/base_site.html" %}
> or an {% extend super %}

I'm not sure if it's what you want, but... I've got a base ui
application with a ui/base.html. Several blocks for the title, logo,
the sidebar, footer, javascript, etc.

Several applications extend that base template. But multiple sites also
want to extend it to change the global logo and footer... The sites
effectively have to override the base template.


The solution: in my ui project I have a ui/realbase.html that is
extended by ui/base.html. The only code in ui/base.html is the
"extends" line! So overriding that one is inexpensive.

The other applications can happily extend ui/base.html and fill in the
blocks that are really from ui/realbase.html. And my site can override
ui/base.html and fill in the logo block and the footer block (which are
normally not touched by the applications).


I hope I'm clear enough without a code example. The code, should you
want to take a look, is at http://pypi.python.org/pypi/lizard-ui

Reinout


--
Reinout van Rees - rei...@vanrees.org - http://reinout.vanrees.org
Programmer at http://www.nelen-schuurmans.nl
"Military engineers build missiles. Civil engineers build targets"

Alessandro Ronchi

unread,
Aug 6, 2010, 8:00:34 AM8/6/10
to django...@googlegroups.com
2010/8/6 Reinout van Rees <rei...@vanrees.org>:

> The solution: in my ui project I have a ui/realbase.html that is extended by
> ui/base.html.  The only code in ui/base.html is the "extends" line!  So
> overriding that one is inexpensive.

I've used the same solution, but it would be nice to have a tag to
enable those extends without empty templates, for DRY principle and
because usually you don't want to change a library template at all,
and with this you have to move to realbase.html.

Reply all
Reply to author
Forward
0 new messages