Hello Daniel, thanks for your quick answer. I didn't find the documentation to say this explicitly, but maybe I just overlooked the relevant section. I never used blocks that were not defined in the base template before, but now I tried to use templates from a reusable app, and was expecting them to work.
> So where would the content go? How would the templating system know > where to put it? You are right, this argument makes a lot of sense! > 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'. Without an overall block it is true, but if you define one overall 'body' block you are right of course. It looks like I have to wrap the content area of the external templates in a 'body' block, and have to rename the title block etc. to resemble my base template. Thanks for clarifying this! Best Regards, Jesaja Everling On Jan 23, 2:29 pm, Daniel Roseman <[email protected]> wrote: > On Jan 23, 12:57 pm, Jesaja Everling <[email protected]> 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 [email protected]. 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.

