A stock template class that may be useful for web developers is defined in
the Cheetah.Templates.SkeletonPage
module. The SkeletonPage
template class is generated from the following Cheetah source code:
##doc-module: A Skeleton HTML page template, that provides basic structure and utility methods. ################################################################################ #extends Cheetah.Templates._SkeletonPage #implements respond ################################################################################ #cache id='header' $docType $htmlTag <!-- This document was autogenerated by Cheetah(http://CheetahTemplate.org). Do not edit it directly! Copyright $currentYr - $siteCopyrightName - All Rights Reserved. Feel free to copy any javascript or html you like on this site, provided you remove all links and/or references to $siteDomainName However, please do not copy any content or images without permission. $siteCredits --> #block writeHeadTag <head> <title>$title</title> $metaTags $stylesheetTags $javascriptTags </head> #end block writeHeadTag #end cache header ################# $bodyTag #block writeBody This skeleton page has no flesh. Its body needs to be implemented. #end block writeBody </body> </html>
You can redefine any of the blocks defined in this template by writing a new
template that #extends
SkeletonPage. (As you remember, using
#extends
makes your template implement the .writeBody()
method instead of .respond()
- which happens to be the same method
SkeletonPage expects the page content to be (note the writeBody block in
SkeletonPage).)
#def bodyContents Here's my new body. I've got some flesh on my bones now. #end def bodyContents
All of the $placeholders used in the SkeletonPage
template definition
are attributes or methods of the SkeletonPage
class. You can reimplement
them as you wish in your subclass. Please read the source code of the file
src/Templates/_SkeletonPage.py
before doing so.
You'll need to understand how to use the following methods of the
SkeletonPage
class: $metaTags()
, $stylesheetTags()
,
$javascriptTags()
, and $bodyTag()
. They take the data you
define in various attributes and renders them into HTML tags.
_SkeletonPage.py
.
self._stylesheetLibs
and self._stylesheets
dictionaries.
The keys in self._stylesheets
must be listed in the order that
they should appear in the list self._stylesheetsOrder
, to ensure
that the style rules are defined in the correct order.
self._javascriptTags
and self._javascriptLibs
dictionaries.
Each value in self._javascriptTags
should be a either a code string
to include, or a list containing the JavaScript version number and the code
string. The keys can be anything. The same applies for
self._javascriptLibs
, but the string should be the SRC filename
rather than a code string.
self._bodyTagAttribs
.
The class also provides some convenience methods that can be used as $placeholders in your template definitions:
src
'' argument to a WebKit serverSidePath relative to the
servlet's location. If width and height aren't specified they are
calculated using PIL or ImageMagick if either of these tools are available.
If all your images are stored in a certain directory you can reimplement
this method to append that directory's path to the ``src
'' argument.
Doing so would also insulate your template definitions from changes in your
directory structure.