views:

25

answers:

1

How can I include with Django what Symfony calls 'components' - bits of logic and a template that's not associated with the content of the current page?

For example I want to include a sidebar that displays a list of the top 10 articles on the site. It should always be displayed if the user is looking at either an 'article' page or a 'video' page. Also, the top 10 articles component needs its own CSS and JS as well as producing content.

If I have a base template that contains sections for "content", "css" and "js", and 'article' and 'video' templates that extend the base template and then define "sidebar" blocks inside "content", what's the 'Django' way of going about this?

Thanks

+1  A: 

Custom tags are what you want - specifically, inclusion tags that let you render another template within the current one.

Daniel Roseman
That looks great. Thanks. Will it let me append to the base template's "css" and "js" blocks though?
Roger
There's a built-in include tag already: http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#include
Claude Vedovini
yes, but include includes the whole template - it won't let me append to blocks in the parent template
Roger
So I think if I use a custom tag to update context variables I could put my CSS, JS and content where I want
Roger
... like described here: http://slavus.net/article/django-formmediacontext/ - in the third box down.
Roger