diff doc/xml-templates.txt @ 244:78ae64ef822e

Fixes for the text template docs.
author cmlenz
date Wed, 13 Sep 2006 17:05:21 +0000
parents bbed6d426678
children 4afa86e2ad83
line wrap: on
line diff
--- a/doc/xml-templates.txt
+++ b/doc/xml-templates.txt
@@ -93,6 +93,24 @@
   >>> print tmpl.generate(dict={'foo': 'bar'})
   <em>bar</em>
 
+Another difference is that you can access variables that are not defined, and
+won't get a ``NameError`` exception::
+
+  >>> from genshi.template import TextTemplate
+  >>> tmpl = TextTemplate('${doh}')
+  >>> print tmpl.generate()
+  <BLANKLINE>
+
+You **will** however get a ``NameError`` if you try to call an undefined 
+variable, or do anything else with it, such as accessing its attributes. If you
+need to know whether a variable is defined, you can check its type against the
+``Undefined`` class, for example in an `py:if`_ directive::
+
+  >>> from genshi.template import TextTemplate
+  >>> tmpl = TextTemplate('${type(doh) is Undefined}')
+  >>> print tmpl.generate()
+  True
+
 
 .. _`directives`:
 
Copyright (C) 2012-2017 Edgewall Software