Mercurial > genshi > mirror
comparison doc/xml-templates.txt @ 237:670f543fd8c2 trunk
Flatten outline of XML templating documentation.
author | cmlenz |
---|---|
date | Tue, 12 Sep 2006 15:59:10 +0000 |
parents | 41107d1ba1c8 |
children | 4d81439bc097 |
comparison
equal
deleted
inserted
replaced
236:7fb269e7da81 | 237:670f543fd8c2 |
---|---|
149 naturally to elements in the template. In such cases, the ``py:strip`` | 149 naturally to elements in the template. In such cases, the ``py:strip`` |
150 directive can be used to strip off the unwanted element, or the directive can | 150 directive can be used to strip off the unwanted element, or the directive can |
151 simply be used as an element. | 151 simply be used as an element. |
152 | 152 |
153 | 153 |
154 Available Directives | 154 Conditional Sections |
155 ==================== | 155 ==================== |
156 | 156 |
157 | |
158 Conditional Sections | |
159 -------------------- | |
160 | |
161 .. _`py:if`: | 157 .. _`py:if`: |
162 | 158 |
163 ``py:if`` | 159 ``py:if`` |
164 ````````` | 160 --------- |
165 | 161 |
166 The element is only rendered if the expression evaluates to a truth value:: | 162 The element is only rendered if the expression evaluates to a truth value:: |
167 | 163 |
168 <div> | 164 <div> |
169 <b py:if="foo">${bar}</b> | 165 <b py:if="foo">${bar}</b> |
186 | 182 |
187 .. _`py:choose`: | 183 .. _`py:choose`: |
188 .. _`py:when`: | 184 .. _`py:when`: |
189 .. _`py:otherwise`: | 185 .. _`py:otherwise`: |
190 | 186 |
191 ``py:choose`` / ``py:when`` / ``py:otherwise`` | 187 ``py:choose`` |
192 `````````````````````````````````````````````` | 188 ------------- |
193 | 189 |
194 This set of directives provides advanced contional processing for rendering one | 190 The ``py:choose`` directive, in combination with the directives ``py:when`` |
191 and ``py:otherwise`` provides advanced contional processing for rendering one | |
195 of several alternatives. The first matching ``py:when`` branch is rendered, or, | 192 of several alternatives. The first matching ``py:when`` branch is rendered, or, |
196 if no ``py:when`` branch matches, the ``py:otherwise`` branch is be rendered. | 193 if no ``py:when`` branch matches, the ``py:otherwise`` branch is be rendered. |
197 | 194 |
198 If the ``py:choose`` directive is empty the nested ``py:when`` directives will | 195 If the ``py:choose`` directive is empty the nested ``py:when`` directives will |
199 be tested for truth:: | 196 be tested for truth:: |
225 <span>1</span> | 222 <span>1</span> |
226 </div> | 223 </div> |
227 | 224 |
228 | 225 |
229 Looping | 226 Looping |
230 ------- | 227 ======= |
231 | 228 |
232 .. _`py:for`: | 229 .. _`py:for`: |
233 | 230 |
234 ``py:for`` | 231 ``py:for`` |
235 `````````` | 232 ---------- |
236 | 233 |
237 The element is repeated for every item in an iterable:: | 234 The element is repeated for every item in an iterable:: |
238 | 235 |
239 <ul> | 236 <ul> |
240 <li py:for="item in items">${item}</li> | 237 <li py:for="item in items">${item}</li> |
254 </py:for> | 251 </py:for> |
255 </ul> | 252 </ul> |
256 | 253 |
257 | 254 |
258 Snippet Reuse | 255 Snippet Reuse |
259 ------------- | 256 ============= |
260 | 257 |
261 .. _`py:def`: | 258 .. _`py:def`: |
262 .. _`macros`: | 259 .. _`macros`: |
263 | 260 |
264 ``py:def`` | 261 ``py:def`` |
265 `````````` | 262 ---------- |
266 | 263 |
267 The ``py:def`` directive can be used to create macros, i.e. snippets of | 264 The ``py:def`` directive can be used to create macros, i.e. snippets of |
268 template code that have a name and optionally some parameters, and that can be | 265 template code that have a name and optionally some parameters, and that can be |
269 inserted in other places:: | 266 inserted in other places:: |
270 | 267 |
316 | 313 |
317 .. _Match Templates: | 314 .. _Match Templates: |
318 .. _`py:match`: | 315 .. _`py:match`: |
319 | 316 |
320 ``py:match`` | 317 ``py:match`` |
321 ```````````` | 318 ------------ |
322 | 319 |
323 This directive defines a *match template*: given an XPath expression, it | 320 This directive defines a *match template*: given an XPath expression, it |
324 replaces any element in the template that matches the expression with its own | 321 replaces any element in the template that matches the expression with its own |
325 content. | 322 content. |
326 | 323 |
356 <greeting name="Dude" /> | 353 <greeting name="Dude" /> |
357 </div> | 354 </div> |
358 | 355 |
359 | 356 |
360 Variable Binding | 357 Variable Binding |
361 ---------------- | 358 ================ |
362 | 359 |
363 .. _`with`: | 360 .. _`with`: |
364 | 361 |
365 ``py:with`` | 362 ``py:with`` |
366 ``````````` | 363 ----------- |
367 | 364 |
368 The ``py:with`` directive lets you assign expressions to variables, which can | 365 The ``py:with`` directive lets you assign expressions to variables, which can |
369 be used to make expressions inside the directive less verbose and more | 366 be used to make expressions inside the directive less verbose and more |
370 efficient. For example, if you need use the expression ``author.posts`` more | 367 efficient. For example, if you need use the expression ``author.posts`` more |
371 than once, and that actually results in a database query, assigning the results | 368 than once, and that actually results in a database query, assigning the results |
394 will have the same value it had prior to the ``py:with`` assignment. | 391 will have the same value it had prior to the ``py:with`` assignment. |
395 Effectively, this means that variables are immutable in Genshi. | 392 Effectively, this means that variables are immutable in Genshi. |
396 | 393 |
397 | 394 |
398 Structure Manipulation | 395 Structure Manipulation |
399 ---------------------- | 396 ====================== |
400 | 397 |
401 .. _`py:attrs`: | 398 .. _`py:attrs`: |
402 | 399 |
403 ``py:attrs`` | 400 ``py:attrs`` |
404 ```````````` | 401 ------------ |
405 | 402 |
406 This directive adds, modifies or removes attributes from the element:: | 403 This directive adds, modifies or removes attributes from the element:: |
407 | 404 |
408 <ul> | 405 <ul> |
409 <li py:attrs="foo">Bar</li> | 406 <li py:attrs="foo">Bar</li> |
427 | 424 |
428 | 425 |
429 .. _`py:content`: | 426 .. _`py:content`: |
430 | 427 |
431 ``py:content`` | 428 ``py:content`` |
432 `````````````` | 429 -------------- |
433 | 430 |
434 This directive replaces any nested content with the result of evaluating the | 431 This directive replaces any nested content with the result of evaluating the |
435 expression:: | 432 expression:: |
436 | 433 |
437 <ul> | 434 <ul> |
448 | 445 |
449 | 446 |
450 .. _`py:replace`: | 447 .. _`py:replace`: |
451 | 448 |
452 ``py:replace`` | 449 ``py:replace`` |
453 `````````````` | 450 -------------- |
454 | 451 |
455 This directive replaces the element itself with the result of evaluating the | 452 This directive replaces the element itself with the result of evaluating the |
456 expression:: | 453 expression:: |
457 | 454 |
458 <div> | 455 <div> |
469 | 466 |
470 | 467 |
471 .. _`py:strip`: | 468 .. _`py:strip`: |
472 | 469 |
473 ``py:strip`` | 470 ``py:strip`` |
474 ```````````` | 471 ------------ |
475 | 472 |
476 This directive conditionally strips the top-level element from the output. When | 473 This directive conditionally strips the top-level element from the output. When |
477 the value of the ``py:strip`` attribute evaluates to ``True``, the element is | 474 the value of the ``py:strip`` attribute evaluates to ``True``, the element is |
478 stripped from the output:: | 475 stripped from the output:: |
479 | 476 |