4.3. Template Variables

This is the list of variables that are available to your templates. Additionally, plugins that you are using will add additional variables. To get a complete list of what variables are available in your blog, use the debug renderer by changing the renderer property in your config.py file to debug like this:

py["renderer"] = "debug"

That will tell you all kinds of stuff about the data structures involved in the request. Don't forget to change it back when you're done!

4.3.1. URL Encoding and Escaping of Template Variables

PyBlosxom 1.3 allows you to escape and URL encode any variables by adding "_escaped" or "_urlencoded" to the end of the variable name.

For example, title_escaped is an escaped form of the title with ' (single-quote) replaced with ' and " (double-quote) replaced with ".

title_urlencoded is a URL encoded form of the title which uses the Python urllib.

4.3.2. Variables From config.py

These template variables are available to all templates. They come directly from your config.py file.

Table 4-1. Template variables from config.py

variable namedescriptionexample
blog_descriptionthe description of the blogblosxom with a touch of python
blog_titlethe title of the blogRoughingIT - pyblosxom : /weblogs/tools/pyblosxom
blog_languagethe language of the blogen
blog_encodingthe encoding of the blogiso8859-1
blog_authorthe author of the blog (hopefully you)Joe Dirt
blog_emailthe email address of the author of the blog (feel free to obfuscate it)joe at joe dot com

Additionally, any other properties you set in config.py are available in your templates. If you wanted to create a blog_images variable holding the base url of the directory with all your images:

Example 4-2. creating your own config.py variables

py["blog_images"] = "http://www.joe.com/~joe/images/"

to your config.py file and it would be available in all your templates.

4.3.3. Calculated Template Variables

These template variables are available to all templates as well. They are calculated based on the request.

Table 4-2. Calculated template variables

variable namedescriptionexample
content_typethe content type of this pagetext/html
root_datadirthe root datadir of this page?/home/subtle/blosxom/weblogs/tools/pyblosxom
urlthe PATH_INFO to this pagepyblosxom/weblogs/tools/pyblosxom
flavourthe flavour for this pagehtml
latest_datethe date of the most recent entry that is going to showTue, 15 Nov 2005
latest_w3cdatethe date of the most recent entry that is going to show in w3cdate format2005-11-13T17:50:02Z
latest_rfc822datethe date of the most recent entry that is going to show in RFC 822 formatSun, 13 Nov 2005 17:50 GMT
pi_yrthe four-digit year the user requested2002
pi_mothe month name the user requestedSep
pi_dathe day number the user requested15
pi_blthe entry the user requested to seeweblogs/tools/pyblosxom
pyblosxom_versionthe version number and release date of the pyblosxom version you're using1.2 3/25/2005

4.3.4. Template Variables Only Available in the story Template

These template variables are only available in your story template.

Table 4-3. Variables in the story template

variable namedescriptionexample
titletitle of the entryFirst Post!
filenametemplate file name and path of the entry/home/subtle/blosxom/weblogs/tools/pyblosxom/index.txt
file_pathjust the filename and extensions of the entryindex.txt
fnjust the filename (no extension)index
absolute_paththe category/path of the entryweblogs/tools/pyblosxom
bodythe text of the entryfirst post!
tb_idthe trackback id of the entry_index
paththe category/path of the entryweblogs/tools/pyblosxom
yrthe four digit year of the mtime of this entry2004
mothe month abbreviation of the mtime of this entryJan
mo_numthe month number of the mtime of this entry01
tithe hour and minute of the mtime of this entry16:40
datethe date string of the mtime of this entrySun, 23 May 2004
w3cdatethe date in w3cdate format2005-11-13T17:50:02Z
rfc822datethe date in RFC 822 formatSun, 13 Nov 2005 17:50 GMT
fulltimethe date in YYYYMMDDHHMMSS format20040523164000
timetuplethe time tuple (year, month, month-day, hour, minute, second, week-day, year-day, isdst)(2004, 5, 23, 16, 40, 0, 6, 144, 1)
mtimeseconds since the epoch1085348400.0
dwthe day of the weekSunday
dathe day of the month23

4.3.5. Template Variables From Plugins

Additionally, many plugins will create additional variables. Refer to the plugin's documentation for what variables it creates, where the variables are available, and what the variables do.