Next Chapter | Up | Next Section | Contents

Creating document templates


Document templates are created by calling one of the classes listed in table 11. The source is passed as the first argument. An optional mapping argument may be provided that contains names to be added to the document template namespace when called and default values. An optional third argument may be provided to specify a namespace attribute for the document template. The standard document template creation arguments are listed in table 12.

Standard document template creation arguments.

Argument number

Argument name

Description

1

source_string

or file_name

The document template source. For classes String and HTML, this must be a string. For classes File and HTMLFile, this is the name of an external file.

2

mapping

A mapping object containing initial names and default values for the document template name-space.

3

__name__

A value to use for the __name__ attribute of the document template object. This value can be used by programming tools to identify the object. For example, Zope tracebacks include __name__ values for instances of methods listed in tracebacks.

For classes String and HTML, the default __name__ value is '<string>' and for File and HTMLFile classes, the default value is the file name.

In addition to the standard creation arguments, additional keyword arguments may be provided to provide additional names and default values for the document template name-space. For example, in:

results=DocumentTemplate.HTMLFile('results.dtml',
{'table_name': 'search results', 'database': 'data'},
pid=os.getpid(),
time=time.time
)

A document template is created using server-side-include syntax source from an external file named 'results.dtml' and with an initial name space that included the names 'table_name', 'database', 'pid', and 'time'.

Next Chapter | Up | Next Section | Contents