| 1 |
Vocabulary |
| 2 |
========== |
| 3 |
|
| 4 |
(glossary) (vocabulary) |
| 5 |
|
| 6 |
{ Template} is an informal term meaning a template definition, a |
| 7 |
template instance or a template class. A { template definition} is |
| 8 |
what the human { template maintainer} writes: a string consisting |
| 9 |
of text, placeholders and directives. { Placeholders} are variables |
| 10 |
that will be looked up when the template is filled. { Directives} |
| 11 |
are commands to be executed when the template is filled, or |
| 12 |
instructions to the Cheetah compiler. The conventional suffix for a |
| 13 |
file containing a template definition is { .tmpl}. |
| 14 |
|
| 15 |
There are two things you can do with a template: compile it or fill |
| 16 |
it. { Filling} is the reason you have a template in the first |
| 17 |
place: to get a finished string out of it. Compiling is a necessary |
| 18 |
prerequisite: the { Cheetah compiler} takes a template definition |
| 19 |
and produces Python code to create the finished string. Cheetah |
| 20 |
provides several ways to compile and fill templates, either as one |
| 21 |
step or two. |
| 22 |
|
| 23 |
Cheetah's compiler produces a subclass of {Cheetah.Template} |
| 24 |
specific to that template definition; this is called the { |
| 25 |
generated class}. A { template instance} is an instance of a |
| 26 |
generated class. |
| 27 |
|
| 28 |
If the user calls the {Template} constructor directly (rather than |
| 29 |
a subclass constructor), s/he will get what appears to be an |
| 30 |
instance of {Template} but is actually a subclass created |
| 31 |
on-the-fly. |
| 32 |
|
| 33 |
The user can make the subclass explicit by using the |
| 34 |
"cheetah compile" command to write the template class to a Python |
| 35 |
module. Such a module is called a { .py template module}. |
| 36 |
|
| 37 |
The { Template Definition Language} - or the "Cheetah language" for |
| 38 |
short - is the syntax rules governing placeholders and directives. |
| 39 |
These are discussed in sections language and following in this |
| 40 |
Guide. |
| 41 |
|
| 42 |
To fill a template, you call its { main method}. This is normally |
| 43 |
{.respond()}, but it may be something else, and you can use the |
| 44 |
{#implements} directive to choose the method name. (Section |
| 45 |
inheritanceEtc.implements. |
| 46 |
|
| 47 |
A { template-servlet} is a .py template module in a Webware servlet |
| 48 |
directory. Such templates can be filled directly through the web by |
| 49 |
requesting the URL. "Template-servlet" can also refer to the |
| 50 |
instance being filled by a particular web request. If a Webware |
| 51 |
servlet that is not a template-servlet invokes a template, that |
| 52 |
template is not a template-servlet either. |
| 53 |
|
| 54 |
A { placeholder tag} is the substring in the template definition |
| 55 |
that is the placeholder, including the start and end delimeters (if |
| 56 |
there is an end delimeter). The { placeholder name} is the same but |
| 57 |
without the delimeters. |
| 58 |
|
| 59 |
Placeholders consist of one or more { identifiers} separated by |
| 60 |
periods (e.g., {a.b}). Each identifier must follow the same rules |
| 61 |
as Python identifiers; that is, a letter or underscore followed by |
| 62 |
one or more letters, digits or underscores. (This is the regular |
| 63 |
expression ``[A-Za-z_][A-Za-z0-9_]*``.) |
| 64 |
|
| 65 |
The first (or only) identifier of a placeholder name represents a { |
| 66 |
variable} to be looked up. Cheetah looks up variables in various { |
| 67 |
namespaces}: the searchList, local variables, and certain other |
| 68 |
places. The searchList is a list of objects ({ containers}) with |
| 69 |
attributes and/or keys: each container is a namespace. Every |
| 70 |
template instance has exactly one searchList. Identifiers after the |
| 71 |
first are looked up only in the parent object. The final value |
| 72 |
after all lookups have been performed is the { placeholder value}. |
| 73 |
|
| 74 |
Placeholders may occur in three positions: top-level, expression |
| 75 |
and LVALUE. { Top-level} placeholders are those in ordinary text |
| 76 |
("top-level text"). { Expression} placeholders are those in Python |
| 77 |
expressions. { LVALUE} placeholders are those naming a variable to |
| 78 |
receive a value. (LVALUE is computerese for |
| 79 |
"the left side of the equal sign".) Section |
| 80 |
language.placeholders.positions explains the differences between |
| 81 |
these three positions. |
| 82 |
|
| 83 |
The routine that does the placeholder lookups is called the { |
| 84 |
NameMapper}. Cheetah's NameMapper supports universal dotted |
| 85 |
notation and autocalling. { Universal dotted notation} means that |
| 86 |
keys may be written as if they were attributes: {a.b} instead of |
| 87 |
{a['b']}. { Autocalling} means that if any identifier's value is |
| 88 |
found to be a function or method, Cheetah will call it without |
| 89 |
arguments if there is no ``()`` following. More about the |
| 90 |
NameMapper is in section language.namemapper. |
| 91 |
|
| 92 |
Some directives are multi-line, meaning they have a matching { |
| 93 |
#end} tag. The lines of text between the start and end tags is the |
| 94 |
{ body} of the directive. Arguments on the same line as the start |
| 95 |
tag, in contrast, are considered part of the directive tag. More |
| 96 |
details are in section language.directives.syntax (Directive Syntax |
| 97 |
Rules). |
| 98 |
|
| 99 |
|