On Sep 18, 11:23 am, "Daniele Procida" <[EMAIL PROTECTED]>
wrote:
> Maybe if I explain what I'm doing it will help.
>
> Django CMS uses a base template, base.html. base.html is:
>
> <http://trac.django-cms.org/trac/browser/trunk/cms/templates/cms/base....>
>
> What I would like is to devolve bits of it to child templates. So
> instead of listing stylesheets in the <head>, I thought I would be able
> to insert a:
>
>     {% block stylesheets %}{% endblock %}
>
> in the head, and place the stylesheets in a block in a template that
> extends base.html. At any rate, this is what I gathered was the way to
> do this.
>
> This way - I thought - I'd be able to have blocks available for things
> that can sensibly be reused in different templates, like stylsheets,
> navigation menus, and so on. But clearly I'm missing some conceptual leap.

No, you have this the wrong way round.

You call the template at the 'top' of the inheritance tree. That
template extends another, and so on right to the 'bottom' of the tree
which might be called something like 'base.html'. The template
rendering system steps through the tree until it finds a template that
doesn't extend any others, then finds the blocks and fills them with
content from the children. However you can't have multiple sub-trees -
so your stylesheets section can't be filled by stylesheets.html while
your body is filled by body.html, this can't work. There can only be
one inheritance chain, and you call the *child* at the end of the
chain, not the parent.

You might benefit from re-reading the documentation on template
inheritance:
http://docs.djangoproject.com/en/dev/topics/templates/#id1

Your use case sounds like it would be better fulfilled by using either
the {% include %} tag, which just includes another rendered template -
see http://docs.djangoproject.com/en/dev/ref/templates/builtins/#include
- or custom inclusion template tags (http://docs.djangoproject.com/en/
dev/howto/custom-template-tags/#inclusion-tags) which do much the same
while allowing you to separately control the context.

> By the way - having been looking at older documentation and discussion
> of this, it used to be that:
>
>     {% extends "whatever.html" %}
>
> was once:
>
>     {% extends "whatever" %}
>
> See for example: <http://jeffcroft.com/blog/2006/feb/25/django-templates-
> the-power-of-inheritance/>
>
> Was this changed so that any filename extension could be used, not just .html?

Yes - the template language can be used to create any format of file,
eg CSV, XML, or whatever.

--
DR.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to