-
Book Overview & Buying
-
Table Of Contents
Django 1.0 Template Development
Though we saw the limitations of using include files earlier in this chapter, there are times when they can be useful. If you have a piece of content that you need to include in some child templates, it may not make sense to create extra parent/child relationships just to drop in this content. Let's look at two options that Django provides us to easily include content.
To take the contents of a template file and put it into another template, use the include tag. Pass the tag a template file name to include just like you did with the extends tag:
{% include "menu.html" %}In this hypothetical example, the menu.html file will be loaded the same way other templates are loaded by the template engine. The location of the file is relative to the TEMPLATE_DIRS setting, and the file is parsed by the template engine using the same context variables as the template that called it.
Because the include files are also rendered with the context, you can use template tags...
Change the font size
Change margin width
Change background colour