comparison doc/xml-templates.txt @ 395:a81675590258 experimental-inline

inline branch: Merged [439:479/trunk].
author cmlenz
date Thu, 28 Dec 2006 18:17:10 +0000
parents 94639584725a
children ee17693d2976 3eb30e4ece8c
comparison
equal deleted inserted replaced
359:e9101f20b796 395:a81675590258
72 Python_ expressions can be used in text and attribute values. An expression is 72 Python_ expressions can be used in text and attribute values. An expression is
73 substituted with the result of its evaluation against the template data. 73 substituted with the result of its evaluation against the template data.
74 Expressions need to prefixed with a dollar sign (``$``) and usually enclosed in 74 Expressions need to prefixed with a dollar sign (``$``) and usually enclosed in
75 curly braces (``{…}``). 75 curly braces (``{…}``).
76 76
77 If the expression starts with a letter and contains only letters and digits, 77 If the expression starts with a letter and contains only letters, digits, dots,
78 the curly braces may be omitted. In all other cases, the braces are required so 78 and underscores, the curly braces may be omitted. In all other cases, the
79 that the template processors knows where the expression ends:: 79 braces are required so that the template processor knows where the expression
80 ends::
80 81
81 >>> from genshi.template import MarkupTemplate 82 >>> from genshi.template import MarkupTemplate
82 >>> tmpl = MarkupTemplate('<em>${items[0].capitalize()} item</em>') 83 >>> tmpl = MarkupTemplate('<em>${items[0].capitalize()} item</em>')
83 >>> print tmpl.generate(items=['first', 'second']) 84 >>> print tmpl.generate(items=['first', 'second'])
84 <em>First item</em> 85 <em>First item</em>
121 Directives are elements and/or attributes in the template that are identified 122 Directives are elements and/or attributes in the template that are identified
122 by the namespace ``http://genshi.edgewall.org/``. They can affect how the 123 by the namespace ``http://genshi.edgewall.org/``. They can affect how the
123 template is rendered in a number of ways: Genshi provides directives for 124 template is rendered in a number of ways: Genshi provides directives for
124 conditionals and looping, among others. 125 conditionals and looping, among others.
125 126
126 To use directives in a template, the namespace should be declared, which is 127 To use directives in a template, the namespace must be declared, which is
127 usually done on the root element:: 128 usually done on the root element::
128 129
129 <html xmlns="http://www.w3.org/1999/xhtml" 130 <html xmlns="http://www.w3.org/1999/xhtml"
130 xmlns:py="http://genshi.edgewall.org/" 131 xmlns:py="http://genshi.edgewall.org/"
131 lang="en"> 132 lang="en">
300 <p class="greeting"> 301 <p class="greeting">
301 Hello, everyone else! 302 Hello, everyone else!
302 </p> 303 </p>
303 </div> 304 </div>
304 305
305 If a macro doesn't require parameters, it can be defined as well as called 306 If a macro doesn't require parameters, it can be defined without the
306 without the parenthesis. For example:: 307 parenthesis. For example::
307 308
308 <div> 309 <div>
309 <p py:def="greeting" class="greeting"> 310 <p py:def="greeting" class="greeting">
310 Hello, world! 311 Hello, world!
311 </p> 312 </p>
312 ${greeting} 313 ${greeting()}
313 </div> 314 </div>
314 315
315 The above would be rendered to:: 316 The above would be rendered to::
316 317
317 <div> 318 <div>
Copyright (C) 2012-2017 Edgewall Software