On Jan 23, 12:57 pm, Jesaja Everling <jeverl...@gmail.com> wrote:
> Hello all,
>
> I'm a little confused about how the template engine handles blocks in
> child templates.
> I always thought that if you define a block in a child template that
> isn't defined in a template the child template extends, the block is
> just rendered as-is.

I don't know why you'd think that, when the documentation explicitly
says otherwise.

> Otherwise, you would have to define every block you intend to use in
> the parent template, which doesn't really makes sense in my opinion;
> especially if you want to include reusable apps that come with their
> own templates.
> Here for example, I would expect the child block to be rendered as
> well as the HTML that is not contained inside a block. Instead, only
> the block from the parent template is rendered.
>
> parent.html:
> {% block parent %}
> <p>this is in parent.html, in block parent</p>
> {% endblock %}
>
> child.html:
> {% extends "parent.html" %}
> {% block child %}
> <p>this is in child.html, in block child</p>
> {% endblock %}
> <p>this is in child.html, but in no block</p>

So where would the content go? How would the templating system know
where to put it?


> What wonders me even more is that if you have multiple levels of
> inheritance, a block in a child template is only rendered if it is
> defined in the top-most base template. This means that you have to
> define all blocks you are ever going to use in your base template.
> Is this really the intended behavior, that blocks in child templates
> are only rendered if they have been defined in the top-most parent
> template?

This is simply not true at all. Don't forget that child templates can
define their *own* blocks. So the top-level template, for example,
just has to define eg one overall 'body' area. Then the section-
specific child template, *inside* the content block, defines eg 'menu'
and 'content'. Then the article-level child template defines
'headline' and 'text'.
--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to