On Thu, Sep 18, 2008, Daniel Roseman <[EMAIL PROTECTED]> wrote:

>
>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.

Oh - thanks. This is the first time I've really understood this. Maybe
other people have understood this more easily, but it would certainly
have helped me if the basic documentation made clearer that:

*   templates are called in a chain from child to parent (i.e. base)
*   the chain is just that, a one-dimensional line of inheritance

>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.

Yes, I think that some of what I need to do is best done in an include.

Thanks again.

Daniele


--~--~---------~--~----~------------~-------~--~----~
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