comparison doc/templating.txt @ 960:6b6be8818bdd

more info
author Richard Jones <richard@users.sourceforge.net>
date Tue, 20 Aug 2002 08:09:36 +0000
parents 81d860e61f0b
children 7d68f88f0642
comparison
equal deleted inserted replaced
959:81d860e61f0b 960:6b6be8818bdd
1 ========================== 1 ==========================
2 HTML Templating Mechanisms 2 HTML Templating Mechanisms
3 ========================== 3 ==========================
4 4
5 :Version: $Revision: 1.6 $ 5 :Version: $Revision: 1.7 $
6 6
7 Current Situation and Issues 7 Current Situation and Issues
8 ============================ 8 ============================
9 9
10 Syntax 10 Syntax
87 <td tal:content="message/title">subject</td> 87 <td tal:content="message/title">subject</td>
88 <td tal:content="message/created">received date</td> 88 <td tal:content="message/created">received date</td>
89 </tr> 89 </tr>
90 </table> 90 </table>
91 91
92 PageTemplates in a Nutshell
93 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
94
95 PageTemplates consist of three technologies:
96
97 TAL - Template Attribute Language
98 This is the syntax which is woven into the HTML using the ``tal:`` tag
99 attributes. A TAL parser pulls out the TAL commands from the attributes
100 runs them using some expression engine.
101
102 TALES - TAL Expression Language
103 The expression engine used in this case is TALES, which runs the expressions
104 that form the tag attribute values. TALES expressions come in three
105 flavours:
106
107 Path Expressions - eg. ``foo/bar/frozz``
108 These are object attribute / item accesses. Roughly speaking, the path
109 ``foo/bar/frozz`` is broken into parts ``foo``, ``bar`` and ``frozz``. The
110 ``foo`` part is the root of the expression. We then look for a ``bar``
111 attribute on foo, or failing that, a bar item (as in foo['bar']). If that
112 fails, the path expression fails. When we get to the end, the object we're
113 left with is evaluated to get a string - methods are called, objects are
114 stringified. Path expressions may have an optional ``path:`` prefix, though
115 they are the default expression type, so it's not necessary.
116
117 String Expressions - eg. ``string:hello ${user/name}``
118 These expressions are simple string interpolations (though they can be just
119 plain strings with no interpolation if you want. The expression in the
120 ``${ ... }`` is just a path expression as above.
121
122 Python Expressions - eg. ``python: 1+1``
123 These expressions give the full power of Python. All the "root level"
124 variables are available, so ``python:foo.bar.frozz()`` might be equivalent
125 to ``foo/bar/frozz``, assuming that ``frozz`` is a method.
126
127 PageTemplates
128 The PageTemplates module glues together TAL and TALES.
129
92 130
93 Implementation 131 Implementation
94 ~~~~~~~~~~~~~~ 132 ~~~~~~~~~~~~~~
95 133
96 I'm envisaging an infrastructure layer where each template has the following 134 I'm envisaging an infrastructure layer where each template has the following
97 variables defined: 135 "root level" (that is, driectly accessible in the TALES namespace) variables
98 136 defined:
137
138 *user*
139 the current user node as an HTMLItem instance
99 *class* 140 *class*
100 the current class of node being displayed 141 the current class of node being displayed as an HTMLClass instance
101 *item* 142 *item*
102 the current node from the database, if we're viewing a specific node 143 the current node from the database, if we're viewing a specific node, as an
144 HTMLItem instance
103 (*classname*) 145 (*classname*)
104 the current node is also available under its classname, so a *user* node 146 the current node is also available under its classname, so a *user* node
105 would also be available under the name *user*. 147 would also be available under the name *user*. This is also an HTMLItem
148 instance.
106 *form* 149 *form*
107 the current CGI form information 150 the current CGI form information as a mapping of form argument name to value
108 *instance* 151 *instance*
109 the current instance 152 the current instance
110 *db* 153 *db*
111 the current open database 154 the current open database
112 *config* 155 *config*
113 the current instance config 156 the current instance config
114 *util* 157 *util*
115 utility methods 158 utility methods
159 *modules*
160 Python modules made available (XXX: not sure what's actually in there tho)
116 161
117 Accesses through a class (either through *class* or *db.<classname>*): 162 Accesses through a class (either through *class* or *db.<classname>*):
118 163
119 class HTMLClass: 164 class HTMLClass:
120 def __getattr__(self, attr): 165 def __getattr__(self, attr):

Roundup Issue Tracker: http://roundup-tracker.org/