Skip to content

Commit c04def9

Browse files
committed
Expanded and edited the Chameleon section.
1 parent 2aa7360 commit c04def9

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

docs/scenarios/web.rst

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,27 +416,49 @@ into the corresponding block in the :file:`base.html` page.
416416

417417
Chameleon
418418
---------
419-
`Chameleon <https://chameleon.readthedocs.org/>`_ is an HTML/XML template engine for Python. It’s designed to generate the document output of a web application, typically HTML markup or XML.
419+
`Chameleon <https://chameleon.readthedocs.org/>`_ Page Templates are an HTML/XML template
420+
engine implementation of the `Template Attribute Language (TAL) <http://en.wikipedia.org/wiki/Template_Attribute_Language>`_,
421+
`TAL Expression Syntax (TALES) <http://chameleon.readthedocs.org/en/latest/reference.html#expressions-tales>`_,
422+
and `Macro Expansion TAL (Metal) <http://chameleon.readthedocs.org/en/latest/reference.html#macros-metal>` syntaxes.
420423

421-
The language used is page templates, originally a Zope invention, but available here as a standalone library that you can use in any script or application running Python 2.5 and up (including 3.x and pypy). It comes with a set of new features, too.
424+
Chameleon is available for Python 2.5 and up (including 3.x and pypy), and
425+
is commonly used by the `Pyramid Framework <http://docs.pylonsproject.org/projects/pyramid/en/latest/>`_.
422426

423-
The template engine compiles templates into Python byte-code and is optimized for speed. For a complex template language, the performance is very good.
427+
Page Templates add within your document structure special element attributes
428+
and text markup. Using a set of simple language constructs, you control the
429+
document flow, element repetition, text replacement and translation. Because
430+
of the attribute-based syntax, unrendered page templates are valid HTML and can
431+
be viewed in a browser and even edited in WYSIWYG editors. This can make
432+
round-trip collaboration with designers and prototyping in a browser easier.
424433

425-
The *page templates* language is used within your document structure
426-
as special element attributes and text markup. Using a set of simple
427-
language constructs, you control the document flow, element
428-
repetition, text replacement and translation.
434+
The basic TAL language is simple enough to grasp from an example:
429435

430-
.. note:: If you've used page templates in a Zope environment previously, note that Chameleon uses Python as the default expression language (instead of *path* expressions).
436+
.. code-block:: html
431437

432-
The basic language (known as the *template attribute language* or TAL)
433-
is simple enough to grasp from an example:
438+
<html>
439+
<body>
440+
<h1>Hello, <span tal:replace="context.name">World</span>!</h1>
441+
<table>
442+
<tr tal:repeat="row 'apple', 'banana', 'pineapple'">
443+
<td tal:repeat="col 'juice', 'muffin', 'pie'">
444+
<span tal:replace="row.capitalize()" /> <span tal:replace="col" />
445+
</td>
446+
</tr>
447+
</table>
448+
</body>
449+
</html>
450+
451+
452+
The `<span tal:replace="expression" />` pattern for text insertion is common
453+
enough that if you do not require strict validity in your unrendered templates,
454+
you can replace it with a more terse and readable syntax that uses the pattern
455+
`${expression}`, as follows:
434456

435457
.. code-block:: html
436458

437459
<html>
438460
<body>
439-
<h1>Hello, ${'world'}!</h1>
461+
<h1>Hello, ${world}!</h1>
440462
<table>
441463
<tr tal:repeat="row 'apple', 'banana', 'pineapple'">
442464
<td tal:repeat="col 'juice', 'muffin', 'pie'">
@@ -447,6 +469,10 @@ is simple enough to grasp from an example:
447469
</body>
448470
</html>
449471

472+
473+
But keep in mind that the full `<span tal:replace="expression">Default Text</span>`
474+
syntax allows for default content in the unrendered template.
475+
450476
.. rubric:: References
451477

452478
.. [1] `The mod_python project is now officially dead <http://blog.dscpl.com.au/2010/06/modpython-project-is-now-officially.html>`_

0 commit comments

Comments
 (0)