# HG changeset patch
# User cmlenz
# Date 1236589063 0
# Node ID c42693ee739d9137eb94a3ca1792da7afdf11b27
# Parent 68f652fa9e6c541fb7f7185afc2e3382c3babe48
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