annotate doc/templates.txt @ 703:af57b12e3dd2 experimental-match-fastpaths

merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
author aflett
date Mon, 31 Mar 2008 22:47:50 +0000
parents 717bbfe5bbdc
children 70a172ab5705 967236817c6a
rev   line source
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
1 .. -*- mode: rst; encoding: utf-8 -*-
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
2
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
3 ========================
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
4 Genshi Templating Basics
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
5 ========================
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
6
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
7 Genshi provides a template engine that can be used for generating either
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
8 markup (such as HTML_ or XML_) or plain text. While both share some of the
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
9 syntax (and much of the underlying implementation) they are essentially
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
10 separate languages.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
11
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
12 .. _html: http://www.w3.org/html/
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
13 .. _xml: http://www.w3.org/XML/
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
14
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
15 This document describes the common parts of the template engine and will be most
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
16 useful as reference to those developing Genshi templates. Templates are XML or
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
17 plain text files that include processing directives_ that affect how the
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
18 template is rendered, and template expressions_ that are dynamically substituted
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
19 by variable data.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
20
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
21
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
22 .. contents:: Contents
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
23 :depth: 3
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
24 .. sectnum::
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
25
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
26 --------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
27 Synopsis
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
28 --------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
29
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
30 A Genshi *markup template* is a well-formed XML document with embedded Python
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
31 used for control flow and variable substitution. Markup templates should be
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
32 used to generate any kind of HTML or XML output, as they provide many advantages
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
33 over simple text-based templates (such as automatic escaping of strings).
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
34
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
35 The following illustrates a very basic Genshi markup template:
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
36
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
37 .. code-block:: genshi
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
38
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
39 <?python
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
40 title = "A Genshi Template"
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
41 fruits = ["apple", "orange", "kiwi"]
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
42 ?>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
43 <html xmlns:py="http://genshi.edgewall.org/">
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
44 <head>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
45 <title py:content="title">This is replaced.</title>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
46 </head>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
47
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
48 <body>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
49 <p>These are some of my favorite fruits:</p>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
50 <ul>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
51 <li py:for="fruit in fruits">
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
52 I like ${fruit}s
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
53 </li>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
54 </ul>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
55 </body>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
56 </html>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
57
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
58 This example shows:
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
59
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
60 (a) a Python code block, using a processing instruction
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
61 (b) the Genshi namespace declaration
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
62 (c) usage of templates directives (``py:content`` and ``py:for``)
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
63 (d) an inline Python expression (``${fruit}``).
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
64
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
65 The template would generate output similar to this:
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
66
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
67 .. code-block:: genshi
445
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
68
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
69 <html>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
70 <head>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
71 <title>A Genshi Template</title>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
72 </head>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
73
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
74 <body>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
75 <p>These are some of my favorite fruits:</p>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
76 <ul>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
77 <li>I like apples</li>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
78 <li>I like oranges</li>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
79 <li>I like kiwis</li>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
80 </ul>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
81 </body>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
82 </html>
ec7890aa7c0b Add documentation page on the plugin API.
cmlenz
parents: 442
diff changeset
83
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
84 A *text template* is a simple plain text document that can also contain embedded
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
85 Python code. Text templates can be used to generate simple *non-markup* text
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
86 formats, such as the body of an plain text email. For example:
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
87
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
88 .. code-block:: genshitext
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
89
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
90 Dear $name,
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
91
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
92 These are some of my favorite fruits:
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
93 #for fruit in fruits
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
94 * $fruit
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
95 #end
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
96
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
97
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
98 ----------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
99 Python API
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
100 ----------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
101
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
102 The Python code required for templating with Genshi is generally based on the
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
103 following pattern:
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
104
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
105 * Attain a ``MarkupTemplate`` or ``TextTemplate`` object from a string or
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
106 file-like object containing the template source. This can either be done
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
107 directly, or through a ``TemplateLoader`` instance.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
108 * Call the ``generate()`` method of the template, passing any data that should
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
109 be made available to the template as keyword arguments.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
110 * Serialize the resulting stream using its ``render()`` method.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
111
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
112 For example:
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
113
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
114 .. code-block:: pycon
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
115
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
116 >>> from genshi.template import MarkupTemplate
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
117 >>> tmpl = MarkupTemplate('<h1>Hello, $name!</h1>')
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
118 >>> stream = tmpl.generate(name='world')
592
1da8de3e5e51 Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents: 545
diff changeset
119 >>> print stream.render('xhtml')
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
120 <h1>Hello, world!</h1>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
121
592
1da8de3e5e51 Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents: 545
diff changeset
122 .. note:: See the Serialization_ section of the `Markup Streams`_ page for
1da8de3e5e51 Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents: 545
diff changeset
123 information on configuring template output options.
1da8de3e5e51 Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents: 545
diff changeset
124
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
125 Using a text template is similar:
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
126
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
127 .. code-block:: pycon
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
128
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
129 >>> from genshi.template import TextTemplate
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
130 >>> tmpl = TextTemplate('Hello, $name!')
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
131 >>> stream = tmpl.generate(name='world')
605
d0345c64da65 Text templates now default to rendering as plain text; it is no longer necessary to explicitly specify the "text" method to the `render()` or `serialize()` method of the generated markup stream. See tickets #62 and #118.
cmlenz
parents: 592
diff changeset
132 >>> print stream
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
133 Hello, world!
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
134
592
1da8de3e5e51 Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents: 545
diff changeset
135 .. note:: If you want to use text templates, you should consider using the
1da8de3e5e51 Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents: 545
diff changeset
136 ``NewTextTemplate`` class instead of simply ``TextTemplate``. See
1da8de3e5e51 Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents: 545
diff changeset
137 the `Text Template Language`_ page.
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
138
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
139 .. _serialization: streams.html#serialization
592
1da8de3e5e51 Add a new syntax for text templates, which is available alongside the old syntax for now. The new syntax is more poweful and flexible, using Django-style directive notation.
cmlenz
parents: 545
diff changeset
140 .. _`Text Template Language`: text-templates.html
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
141 .. _`Markup Streams`: streams.html
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
142
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
143 Using a template loader provides the advantage that “compiled” templates are
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
144 automatically cached, and only parsed again when the template file changes. In
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
145 addition, it enables the use of a *template search path*, allowing template
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
146 directories to be spread across different file-system locations. Using a
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
147 template loader would generally look as follows:
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
148
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
149 .. code-block:: python
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
150
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
151 from genshi.template import TemplateLoader
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
152 loader = TemplateLoader([templates_dir1, templates_dir2])
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
153 tmpl = loader.load('test.html')
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
154 stream = tmpl.generate(title='Hello, world!')
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
155 print stream.render()
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
156
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
157 See the `API documentation <api/index.html>`_ for details on using Genshi via
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
158 the Python API.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
159
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
160
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
161 .. _`expressions`:
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
162
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
163 ------------------------------------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
164 Template Expressions and Code Blocks
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
165 ------------------------------------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
166
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
167 Python_ expressions can be used in text and directive arguments. An expression
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
168 is substituted with the result of its evaluation against the template data.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
169 Expressions in text (which includes the values of non-directive attributes) need
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
170 to prefixed with a dollar sign (``$``) and usually enclosed in curly braces
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
171 (``{…}``).
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
172
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
173 .. _python: http://www.python.org/
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
174
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
175 If the expression starts with a letter and contains only letters, digits, dots,
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
176 and underscores, the curly braces may be omitted. In all other cases, the
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
177 braces are required so that the template processor knows where the expression
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
178 ends:
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
179
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
180 .. code-block:: pycon
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
181
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
182 >>> from genshi.template import MarkupTemplate
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
183 >>> tmpl = MarkupTemplate('<em>${items[0].capitalize()} item</em>')
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
184 >>> print tmpl.generate(items=['first', 'second'])
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
185 <em>First item</em>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
186
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
187 Expressions support the full power of Python. In addition, it is possible to
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
188 access items in a dictionary using “dotted notation” (i.e. as if they were
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
189 attributes), and vice-versa (i.e. access attributes as if they were items in a
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
190 dictionary):
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
191
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
192 .. code-block:: pycon
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
193
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
194 >>> from genshi.template import MarkupTemplate
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
195 >>> tmpl = MarkupTemplate('<em>${dict.foo}</em>')
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
196 >>> print tmpl.generate(dict={'foo': 'bar'})
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
197 <em>bar</em>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
198
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
199 Because there are two ways to access either attributes or items, expressions
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
200 do not raise the standard ``AttributeError`` or ``IndexError`` exceptions, but
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
201 rather an exception of the type ``UndefinedError``. The same kind of error is
476
1bb01fce61ba Update documentation to reflect changes in [573].
cmlenz
parents: 445
diff changeset
202 raised when you try to use a top-level variable that is not in the context data.
1bb01fce61ba Update documentation to reflect changes in [573].
cmlenz
parents: 445
diff changeset
203 See `Error Handling`_ below for details on how such errors are handled.
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
204
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
205
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
206 .. _`code blocks`:
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
207
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
208 Code Blocks
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
209 ===========
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
210
609
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
211 Templates also support full Python code blocks, using the ``<?python ?>``
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
212 processing instruction in XML templates:
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
213
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
214 .. code-block:: genshi
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
215
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
216 <div>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
217 <?python
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
218 from genshi.builder import tag
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
219 def greeting(name):
649
717bbfe5bbdc Fix typo in docs. Closes #153.
cmlenz
parents: 609
diff changeset
220 return tag.b('Hello, %s!' % name) ?>
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
221 ${greeting('world')}
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
222 </div>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
223
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
224 This will produce the following output:
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
225
609
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
226 .. code-block:: xml
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
227
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
228 <div>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
229 <b>Hello, world!</b>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
230 </div>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
231
609
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
232 In text templates (although only those using the new syntax introduced in
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
233 Genshi 0.5), code blocks use the special ``{% python %}`` directive:
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
234
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
235 .. code-block:: genshitext
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
236
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
237 {% python
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
238 from genshi.builder import tag
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
239 def greeting(name):
649
717bbfe5bbdc Fix typo in docs. Closes #153.
cmlenz
parents: 609
diff changeset
240 return 'Hello, %s!' % name
609
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
241 %}
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
242 ${greeting('world')}
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
243
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
244 This will produce the following output::
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
245
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
246 Hello, world!
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
247
6d4877844e28 Add support for Python code blocks in text templates using the new syntax.
cmlenz
parents: 606
diff changeset
248
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
249 Code blocks can import modules, define classes and functions, and basically do
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
250 anything you can do in normal Python code. What code blocks can *not* do is to
606
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
251 produce content that is emitted directly tp the generated output.
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
252
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
253 .. note:: Using the ``print`` statement will print to the standard output
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
254 stream, just as it does for other Python code in your application.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
255
476
1bb01fce61ba Update documentation to reflect changes in [573].
cmlenz
parents: 445
diff changeset
256 Unlike expressions, Python code in ``<?python ?>`` processing instructions can
1bb01fce61ba Update documentation to reflect changes in [573].
cmlenz
parents: 445
diff changeset
257 not use item and attribute access in an interchangeable manner. That means that
1bb01fce61ba Update documentation to reflect changes in [573].
cmlenz
parents: 445
diff changeset
258 “dotted notation” is always attribute access, and vice-versa.
1bb01fce61ba Update documentation to reflect changes in [573].
cmlenz
parents: 445
diff changeset
259
1bb01fce61ba Update documentation to reflect changes in [573].
cmlenz
parents: 445
diff changeset
260 The support for Python code blocks in templates is not supposed to encourage
1bb01fce61ba Update documentation to reflect changes in [573].
cmlenz
parents: 445
diff changeset
261 mixing application code into templates, which is generally considered bad
1bb01fce61ba Update documentation to reflect changes in [573].
cmlenz
parents: 445
diff changeset
262 design. If you're using many code blocks, that may be a sign that you should
1bb01fce61ba Update documentation to reflect changes in [573].
cmlenz
parents: 445
diff changeset
263 move such code into separate Python modules.
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
264
545
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 510
diff changeset
265 If you'd rather not allow the use of Python code blocks in templates, you can
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 510
diff changeset
266 simply set the ``allow_exec`` parameter (available on the ``Template`` and the
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 510
diff changeset
267 ``TemplateLoader`` initializers) to ``False``. In that case Genshi will raise
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 510
diff changeset
268 a syntax error when a ``<?python ?>`` processing instruction is encountered.
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 510
diff changeset
269 But please note that disallowing code blocks in templates does not turn Genshi
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 510
diff changeset
270 into a sandboxable template engine; there are sufficient ways to do harm even
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 510
diff changeset
271 using plain expressions.
619340e2d805 Support for Python code blocks in templates can now be disabled. Closes #123.
cmlenz
parents: 510
diff changeset
272
703
af57b12e3dd2 merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents: 649
diff changeset
273 .. warning:: Unfortunately, code blocks are severely limited when running
af57b12e3dd2 merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents: 649
diff changeset
274 under Python 2.3: For example, it is not possible to access
af57b12e3dd2 merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents: 649
diff changeset
275 variables defined in outer scopes. If you plan to use code blocks
af57b12e3dd2 merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents: 649
diff changeset
276 extensively, it is strongly recommended that you run Python 2.4
af57b12e3dd2 merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents: 649
diff changeset
277 or later.
af57b12e3dd2 merge in trunk up through r818 - fundamentally changed the way MatchSet works, but actually is more consistent now
aflett
parents: 649
diff changeset
278
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
279
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
280 .. _`error handling`:
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
281
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
282 Error Handling
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
283 ==============
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
284
606
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
285 By default, Genshi raises an ``UndefinedError`` if a template expression
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
286 attempts to access a variable that is not defined:
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
287
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
288 .. code-block:: pycon
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
289
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
290 >>> from genshi.template import MarkupTemplate
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
291 >>> tmpl = MarkupTemplate('<p>${doh}</p>')
606
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
292 >>> tmpl.generate().render('xhtml')
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
293 Traceback (most recent call last):
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
294 ...
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
295 UndefinedError: "doh" not defined
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
296
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
297 You can change this behavior by setting the variable lookup mode to "lenient".
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
298 In that case, accessing undefined variables returns an `Undefined` object,
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
299 meaning that the expression does not fail immediately. See below for details.
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
300
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
301 If you need to check whether a variable exists in the template context, use the
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
302 defined_ or the value_of_ function described below. To check for existence of
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
303 attributes on an object, or keys in a dictionary, use the ``hasattr()``,
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
304 ``getattr()`` or ``get()`` functions, or the ``in`` operator, just as you would
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
305 in regular Python code:
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
306
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
307 >>> from genshi.template import MarkupTemplate
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
308 >>> tmpl = MarkupTemplate('<p>${defined("doh")}</p>')
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
309 >>> print tmpl.generate().render('xhtml')
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
310 <p>False</p>
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
311
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
312 .. note:: Lenient error handling was the default in Genshi prior to version 0.5.
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
313 Strict mode was introduced in version 0.4, and became the default in
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
314 0.5. The reason for this change was that the lenient error handling
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
315 was masking actual errors in templates, thereby also making it harder
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
316 to debug some problems.
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
317
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
318
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
319 .. _`lenient`:
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
320
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
321 Lenient Mode
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
322 ------------
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
323
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
324 If you instruct Genshi to use the lenient variable lookup mode, it allows you
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
325 to access variables that are not defined, without raising an ``UndefinedError``.
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
326
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
327 This mode can be chosen by passing the ``lookup='lenient'`` keyword argument to
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
328 the template initializer, or by passing the ``variable_lookup='lenient'``
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
329 keyword argument to the ``TemplateLoader`` initializer:
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
330
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
331 .. code-block:: pycon
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
332
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
333 >>> from genshi.template import MarkupTemplate
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
334 >>> tmpl = MarkupTemplate('<p>${doh}</p>', lookup='lenient')
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
335 >>> print tmpl.generate().render('xhtml')
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
336 <p></p>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
337
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
338 You *will* however get an exception if you try to call an undefined variable, or
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
339 do anything else with it, such as accessing its attributes:
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
340
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
341 .. code-block:: pycon
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
342
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
343 >>> from genshi.template import MarkupTemplate
606
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
344 >>> tmpl = MarkupTemplate('<p>${doh.oops}</p>', lookup='lenient')
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
345 >>> print tmpl.generate().render('xhtml')
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
346 Traceback (most recent call last):
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
347 ...
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
348 UndefinedError: "doh" not defined
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
349
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
350 If you need to know whether a variable is defined, you can check its type
510
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
351 against the ``Undefined`` class, for example in a conditional directive:
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
352
1bdccd3bda00 Use syntax highlighting on all the other doc pages, too.
cmlenz
parents: 476
diff changeset
353 .. code-block:: pycon
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
354
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
355 >>> from genshi.template import MarkupTemplate
606
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
356 >>> tmpl = MarkupTemplate('<p>${type(doh) is not Undefined}</p>',
37ff75bb4301 Changed the default error handling mode to "strict".
cmlenz
parents: 605
diff changeset
357 ... lookup='lenient')
442
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
358 >>> print tmpl.generate().render('xhtml')
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
359 <p>False</p>
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
360
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
361 Alternatively, the built-in functions defined_ or value_of_ can be used in this
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
362 case.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
363
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
364 Custom Modes
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
365 ------------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
366
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
367 In addition to the built-in "lenient" and "strict" modes, it is also possible to
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
368 use a custom error handling mode. For example, you could use lenient error
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
369 handling in a production environment, while also logging a warning when an
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
370 undefined variable is referenced.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
371
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
372 See the API documentation of the ``genshi.template.eval`` module for details.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
373
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
374
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
375 Built-in Functions & Types
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
376 ==========================
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
377
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
378 The following functions and types are available by default in template code, in
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
379 addition to the standard built-ins that are available to all Python code.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
380
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
381 .. _`defined`:
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
382
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
383 ``defined(name)``
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
384 -----------------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
385 This function determines whether a variable of the specified name exists in
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
386 the context data, and returns ``True`` if it does.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
387
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
388 .. _`value_of`:
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
389
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
390 ``value_of(name, default=None)``
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
391 --------------------------------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
392 This function returns the value of the variable with the specified name if
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
393 such a variable is defined, and returns the value of the ``default``
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
394 parameter if no such variable is defined.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
395
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
396 .. _`Markup`:
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
397
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
398 ``Markup(text)``
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
399 ----------------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
400 The ``Markup`` type marks a given string as being safe for inclusion in markup,
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
401 meaning it will *not* be escaped in the serialization stage. Use this with care,
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
402 as not escaping a user-provided string may allow malicious users to open your
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
403 web site to cross-site scripting attacks.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
404
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
405 .. _`Undefined`:
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
406
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
407 ``Undefined``
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
408 ----------------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
409 The ``Undefined`` type can be used to check whether a reference variable is
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
410 defined, as explained in `error handling`_.
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
411
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
412
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
413 .. _`directives`:
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
414
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
415 -------------------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
416 Template Directives
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
417 -------------------
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
418
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
419 Directives provide control flow functionality for templates, such as conditions
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
420 or iteration. As the syntax for directives depends on whether you're using
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
421 markup or text templates, refer to the
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
422 `XML Template Language <xml-templates.html>`_ or
97544725bb7f Back out [510] and instead implement configurable error handling modes. The default is the old 0.3.x behaviour, but more strict error handling is available as an option.
cmlenz
parents:
diff changeset
423 `Text Template Language <text-templates.html>`_ pages for information.
Copyright (C) 2012-2017 Edgewall Software