Compositional Templates Django

19 views
Skip to first unread message

Secret

unread,
Jul 29, 2014, 4:41:08 AM7/29/14
to django...@googlegroups.com

What is the best way to create modular templates?

For example, if I have something like this:

#base file:
{header}
{block content}
{footer}

#main file:
{extends base}
{block content definition}

#product file:
{extends base}
{block content definition}

This is the django way from what I understand - filling in the blanks.

Now, my question is what if I needed a page like this:

{header}
{main}
{product}
{footer}

Basically, the main, and product are both inside the base file. I could try a deep inherit (a page that has main, which then consecutively loads product) but that does not work since the files both define 'content', and that is not possible in Django

Tom Evans

unread,
Jul 29, 2014, 9:54:55 AM7/29/14
to django...@googlegroups.com
If product is a specialisation of main, then it should extend main and
not base. If it is not, I do not understand the question.

It is common to define your base page style, without any content
layout or menu system at all, extend that to add basic layout and
menu, extend *that* to add a specific layout style, and then extend
that for each page in that style that has specific template needs.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages