Changes between Version 21 and Version 22 of MarkupTemplates
- Timestamp:
- Jul 12, 2006, 3:06:03 AM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
MarkupTemplates
v21 v22 13 13 == Template Context == 14 14 15 Rendering a template boils down to applying one or more template files to some input data. This input data is represented as a [wiki:ApiDocs/MarkupTemplate#markup.template:Context Context] object in Markup. A context is basically a stack of dictionaries that manages the namespace scopes during processing: for example, some variable may be a ble under a given name inside a loop, but not outside of that loop.15 Rendering a template boils down to applying one or more template files to some input data. This input data is represented as a [wiki:ApiDocs/MarkupTemplate#markup.template:Context Context] object in Markup. A context is basically a stack of dictionaries that manages the namespace scopes during processing: for example, some variable may be available under a given name inside a loop, but not outside of that loop. 16 16 17 17 Regardless of its stack behavior during templating processing, a context is usually initialized from a single dictionary: … … 108 108 }}} 109 109 110 The rationale behind the second form is that directives not always map naturally to elements in the template. In such cases, the [wiki:MarkupTemplates#pystrip py:strip] directive can be used to strip off the unwanted element, or the directive can simply be used as an element.110 The rationale behind the second form is that directives do not always map naturally to elements in the template. In such cases, the [wiki:MarkupTemplates#pystrip py:strip] directive can be used to strip off the unwanted element, or the directive can simply be used as an element. 111 111 112 112 === `py:content` === … … 171 171 <ul> 172 172 <li class="collapse">Bar</li> 173 </ul> 174 }}} 175 176 Attributes with the value `None` are omitted, so given `foo={'class': None}` in the context for the same template this would produce: 177 178 {{{ 179 #!xml 180 <ul> 181 <li>Bar</li> 173 182 </ul> 174 183 }}} … … 233 242 === `py:choose` / `py:when` / `py:otherwise` === 234 243 235 This set of directives provides advanced contional processing: one of several alternatives is rendered depending on which of the `py:when` directives evaluates to a truth value. 244 This set of directives provides advanced contional processing for rendering one of several alternatives. The first matching `py:when` directive will be rendered or, if no `py:when` directive matches, the `py:otherwise` directive will be rendered. 245 246 If the `py:choose` directive is empty the nested `py:when` directives will be tested for truth: 236 247 237 248 {{{ … … 240 251 <span py:when="0 == 1">0</span> 241 252 <span py:when="1 == 1">1</span> 253 <span py:otherwise="">2</span> 254 </div> 255 }}} 256 257 This would produce the following output: 258 259 {{{ 260 #!xml 261 <div> 262 <span>1</span> 263 </div> 264 }}} 265 266 If the `py:choose` directive contains an expression the nested `py:when` directives will be tested for equality to the parent `py:choose` value: 267 268 {{{ 269 #!xml 270 <div xmlns:py="http://markup.edgewall.org/" py:choose="1"> 271 <span py:when="0">0</span> 272 <span py:when="1">1</span> 242 273 <span py:otherwise="">2</span> 243 274 </div>