# HG changeset patch # User cmlenz # Date 1236589063 0 # Node ID b1e9e3209c6ff76fb0b157ae961372cc2325868b # Parent 92c5d936616b01443f564d5d756705c88cabefa6 Add doc section on expression escaping. Closes #282. diff --git a/doc/templates.txt b/doc/templates.txt --- a/doc/templates.txt +++ b/doc/templates.txt @@ -203,6 +203,44 @@ See `Error Handling`_ below for details on how such errors are handled. +Escaping +======== + +If you need to include a literal dollar sign in the output where Genshi would +normally detect an expression, you can simply add another dollar sign: + +.. code-block:: pycon + + >>> from genshi.template import MarkupTemplate + >>> tmpl = MarkupTemplate('$foo') # Wanted "$foo" as literal output + >>> print tmpl.generate() + Traceback (most recent call last): + ... + UndefinedError: "foo" not defined + >>> tmpl = MarkupTemplate('$$foo') + >>> print tmpl.generate() + $foo + +But note that this is not necessary if the characters following the dollar sign +do not qualify as an expression. For example, the following needs no escaping: + +.. code-block:: pycon + + >>> tmpl = MarkupTemplate('') + >>> print tmpl.generate() + + +On the other hand, Genshi will always replace two dollar signs in text with a +single dollar sign, so you'll need to use three dollar signs to get two in the +output: + +.. code-block:: pycon + + >>> tmpl = MarkupTemplate('') + >>> print tmpl.generate() + + + .. _`code blocks`: Code Blocks