Changeset 6562
- Timestamp:
- 10/20/07 06:05:15 (11 months ago)
- Files:
-
- django/trunk/docs/templates.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/templates.txt
r6533 r6562 12 12 or CheetahTemplate_, you should feel right at home with Django's templates. 13 13 14 .. admonition:: Philosophy 15 16 If you have a background in programming, or if you're used to languages 17 like PHP which mix programming code directly into HTML, you'll want to 18 bear in mind that the Django template system is not simply Python embedded 19 into HTML. This is by design: the template system is meant to express 20 presentation, not program logic. 21 22 The Django template system provides tags which function similarly to some 23 programming constructs -- an ``{% if %}`` tag for boolean tests, a ``{% 24 for %}`` tag for looping, etc. -- but these are not simply executed as the 25 corresponding Python code, and the template system will not execute 26 arbitrary Python expressions. Only the tags, filters and syntax listed 27 below are supported by default (although you can add `your own 28 extensions`_ to the template language as needed). 29 14 30 .. _`The Django template language: For Python programmers`: ../templates_python/ 15 31 .. _Smarty: http://smarty.php.net/ 16 32 .. _CheetahTemplate: http://www.cheetahtemplate.org/ 33 .. _your own extensions: ../templates_python/#extending-the-template-system 17 34 18 35 Templates … … 383 400 </tr> 384 401 {% endfor %} 385 402 386 403 Outside of a loop, give the values a unique name the first time you call it, 387 404 then use that name each successive time through:: … … 391 408 <tr class="{% cycle rowcolors %}">...</tr> 392 409 393 You can use any number of values, separated by spaces. Values enclosed in 394 single (') or double quotes (") are treated as string literals, while values 395 without quotes are assumed to refer to context variables. 410 You can use any number of values, separated by spaces. Values enclosed in 411 single (') or double quotes (") are treated as string literals, while values 412 without quotes are assumed to refer to context variables. 396 413 397 414 You can also separate values with commas:: 398 415 399 416 {% cycle row1,row2,row3 %} 400 401 In this syntax, each value will be interpreted as literal text. The 402 comma-based syntax exists for backwards-compatibility, and should not be 417 418 In this syntax, each value will be interpreted as literal text. The 419 comma-based syntax exists for backwards-compatibility, and should not be 403 420 used for new projects. 404 421 … … 478 495 in eachs sub-list into a set of known names. For example, if your context contains 479 496 a list of (x,y) coordinates called ``points``, you could use the following 480 to output the list of points:: 497 to output the list of points:: 481 498 482 499 {% for x, y in points %} 483 500 There is a point at {{ x }},{{ y }} 484 501 {% endfor %} 485 486 This can also be useful if you need to access the items in a dictionary. 502 503 This can also be useful if you need to access the items in a dictionary. 487 504 For example, if your context contained a dictionary ``data``, the following 488 505 would display the keys and values of the dictionary::
