Mercurial > genshi > mirror
comparison doc/templates.txt @ 592:1da8de3e5e51 trunk
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.
author | cmlenz |
---|---|
date | Mon, 13 Aug 2007 12:40:56 +0000 |
parents | 619340e2d805 |
children | d0345c64da65 |
comparison
equal
deleted
inserted
replaced
590:36b5a03534a0 | 592:1da8de3e5e51 |
---|---|
114 .. code-block:: pycon | 114 .. code-block:: pycon |
115 | 115 |
116 >>> from genshi.template import MarkupTemplate | 116 >>> from genshi.template import MarkupTemplate |
117 >>> tmpl = MarkupTemplate('<h1>Hello, $name!</h1>') | 117 >>> tmpl = MarkupTemplate('<h1>Hello, $name!</h1>') |
118 >>> stream = tmpl.generate(name='world') | 118 >>> stream = tmpl.generate(name='world') |
119 >>> print stream.render() | 119 >>> print stream.render('xhtml') |
120 <h1>Hello, world!</h1> | 120 <h1>Hello, world!</h1> |
121 | |
122 .. note:: See the Serialization_ section of the `Markup Streams`_ page for | |
123 information on configuring template output options. | |
121 | 124 |
122 Using a text template is similar: | 125 Using a text template is similar: |
123 | 126 |
124 .. code-block:: pycon | 127 .. code-block:: pycon |
125 | 128 |
126 >>> from genshi.template import TextTemplate | 129 >>> from genshi.template import TextTemplate |
127 >>> tmpl = TextTemplate('Hello, $name!') | 130 >>> tmpl = TextTemplate('Hello, $name!') |
128 >>> stream = tmpl.generate(name='world') | 131 >>> stream = tmpl.generate(name='world') |
129 >>> print stream.render() | 132 >>> print stream.render('text') |
130 Hello, world! | 133 Hello, world! |
131 | 134 |
132 .. note:: See the Serialization_ section of the `Markup Streams`_ page for | 135 .. note:: If you want to use text templates, you should consider using the |
133 information on configuring template output options. | 136 ``NewTextTemplate`` class instead of simply ``TextTemplate``. See |
137 the `Text Template Language`_ page. | |
134 | 138 |
135 .. _serialization: streams.html#serialization | 139 .. _serialization: streams.html#serialization |
140 .. _`Text Template Language`: text-templates.html | |
136 .. _`Markup Streams`: streams.html | 141 .. _`Markup Streams`: streams.html |
137 | 142 |
138 Using a template loader provides the advantage that “compiled” templates are | 143 Using a template loader provides the advantage that “compiled” templates are |
139 automatically cached, and only parsed again when the template file changes. In | 144 automatically cached, and only parsed again when the template file changes. In |
140 addition, it enables the use of a *template search path*, allowing template | 145 addition, it enables the use of a *template search path*, allowing template |