A tour of the templates

Revision as of 20:25, 14 February 2011 by imported>Paulproteus

This is a page about improving or modifying OpenHatch.

We call that "Hacking OpenHatch," and there is a whole category of pages about that.


The OpenHatch site has a lot of Django template files. This page explains what they are and how they work together.

Background knowledge

This page uses the following terminology:

  • A template file is a file (e.g., mysite/base/templates/base/base.html) that usually ends in ".html")
  • Our templates make extensive use of template inheritance. You can read more about that in the Django documentation, or in this nice article. The inheritance feature lets use replaceable, named blocks.
  • The OpenHatch code is broken up into different Django apps. The LAYOUT file explains these apps a little bit.

Who should read this?

You should read this if you are:

  • Writing a new page, and want to get a sense of how things work together
  • Curious to learn how we use Django templates

Begin at the begin: base.html

All web pages that render into HTML eventually extend from base.html. You can look at the current version in Gitorious, on the web.

Important template blocks in the <head> of the document

  • title: If you want your page to have a custom HTML TITLE, override the title block. It gets wrapped inside the whole_title block.
  • js_in_head: You can override this if your page needs to add JavaScript tags to the <head> section of the HTML document. Use sparingly, as putting JavaScript here will cause the browser to wait for the script to load before rendering the document.
  • css: If you want to add custom CSS, you can add it by extending this block. Be sure to call Template:Block.super at the top if you do that, or else you'll accidentally erase a bunch of main site CSS.

Generally useful template blocks for the <body>

  • body_id and body_class: If you want your page to provide a hint to CSS as to what page it is, you can use these.