If you use Cheetah, please support the project and register by clicking here:

14.3 Site frameworks

Web sites are normally arranged hierarchically, with certain features common to every page on the site, other features common to certain sections or subsections, and others unique to each page. You can model this easily with a hierarchy of classes, with specific servlets inheriting from their more general superclasses. Again, you can do this two ways, using Cheetah's Containment approach or Inheritance approach.

In the Inheritance approach, parents provide #blocks and children override them using #def. Each child #extends its immediate parent. Only the leaf servlets need to be under WebKit's document root directory. The superclass servlets can live anywhere in the filesystem that's in the Python path. (You may want to modify your WebKit startup script to add that library directory to your PYTHONPATH before starting WebKit.)

Section 17.7 contains information on a stock template that simplifies defining the basic HTML structure of your web page templates.

In the Containment approach, your hierarchy of servlets are not templates, but each uses one or more templates as it wishes. Children provide callback methods to to produce the various portions of the page that are their responsibility, and parents call those methods. Webware's WebKit.Page and WebKit.SidebarPage classes operate like this.

Note that the two approaches are not compatible! WebKit.Page was not designed to intermix with Cheetah.Templates.SkeletonPage. Choose either one or the other, or expect to do some integration work.

If you come up with a different strategy you think is worth noting in this chapter, let us know.

If you use Cheetah, please support the project and register by clicking here: