Help a Rails refugee - how to do site specific layouts?

0 views
Skip to first unread message

Todd Blanchard

unread,
Nov 12, 2009, 1:35:49 PM11/12/09
to Django users
I like the rails mechanism for specifying page layouts (boilerplate
template that surrounds the currently rendered view).

Its simple and obvious.

I cannot, having read most of two books on django now along with the
website stuff, figure out how to do the same thing in django.

Also, I'm building a multiple-domain site and using the sites module
so I want different layouts for different sites.

Can someone point me an example or a module or something?

Thx

-Todd

Bill Freeman

unread,
Nov 12, 2009, 4:23:13 PM11/12/09
to django...@googlegroups.com
I haven't done rails, but my boilerplate is in a template that is
"extended" by the
page specific templates. In fact, I have multiple levels: section
specific boilerplate
templates that extend a site wide template, with the section specific templates
being extended by the page (type) specific templates.

Look at the "extends" and "block" tags in the template tags reference
and tutorial.

It's seems easy to misunderstand the documentation on these, so let me try a
phrase or two: A template which will be extended provides one or more holes
which the extending templates can fill, by using the block tag. The
extending template
fills it with the block tag. block tags are named so that they can be
matched up. If an
extending template does not fill a particular block in the extended
template, then that
block's content in the extended template is used. If the extending
template uses that
block, then it's content is used instead. Stuff in an extending
template that is not in a
block, or which is in a block that the extended template doesn't have
a block by that name,
is not sent to the browser (is not rendered). See also the variable
block.super, which allows
you to add to rather than replace content from the extended template.

Also see the "include" tag, but if you use it very much, you probably
don't understand extends.

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

Andy Mckay

unread,
Nov 12, 2009, 11:36:44 PM11/12/09
to django...@googlegroups.com
On 09-11-12 10:35 AM, Todd Blanchard wrote:
> I like the rails mechanism for specifying page layouts (boilerplate
> template that surrounds the currently rendered view).
>
> Its simple and obvious.

Use the "extends" tag. If you want rails style boilerplate, there's
always "include"

http://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance
--
Andy McKay
@clearwind
Training: http://clearwind.ca/training/
Zen: http://djangozen.com

Ismail Dhorat

unread,
Nov 13, 2009, 1:37:36 AM11/13/09
to django...@googlegroups.com
Hey man, your question is not entirely clear but:

If you dont want to repeat yourself, you typically would use extend
tags as everyone has said. These templates can be as deep as you want
it, (not sure about the performance impact) but you could have and i
have used this

Base Template
|-----Subtemplate
|---- Micro-template

Your URL calls the last template, which 'extends' the next level up,
which in turn extends the base.

The other option is, using a template tag i.e {% get_options %} and
automatically generating the HTML required (THis could be linked to a
queryset), the documentation on templatetags will help you there.

Regards,
Ismail
Reply all
Reply to author
Forward
0 new messages