22HTML Templating Mechanisms
33==========================
44
5- :Version: $Revision: 1.6 $
5+ :Version: $Revision: 1.7 $
66
77Current Situation and Issues
88============================
@@ -89,22 +89,65 @@ Other fun can be had when you start playing with stuff like:
8989 </tr>
9090 </table>
9191
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+
92130
93131Implementation
94132~~~~~~~~~~~~~~
95133
96134I'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
136+ defined:
98137
138+ *user*
139+ the current user node as an HTMLItem instance
99140*class*
100- the current class of node being displayed
141+ the current class of node being displayed as an HTMLClass instance
101142*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
103145(*classname*)
104146 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.
106149*form*
107- the current CGI form information
150+ the current CGI form information as a mapping of form argument name to value
108151*instance*
109152 the current instance
110153*db*
@@ -113,6 +156,8 @@ variables defined:
113156 the current instance config
114157*util*
115158 utility methods
159+ *modules*
160+ Python modules made available (XXX: not sure what's actually in there tho)
116161
117162Accesses through a class (either through *class* or *db.<classname>*):
118163
0 commit comments