title: mako template recursion: AttributeError: 'Undefined' object has no attribute 'id'
body: <p>I've made a template for representing a tree structure. Each node of the tree has an id, a name, a list of children (tree_children) and an expanded property.</p>
  
  <p>I arranged a few nodes in a tree structure and then called the following function with the root node:</p>
  
  <pre><code>def print_tree_info(oCat, iOffset=0):
      """
      just for testing purposes. print to console
      """
      sOffset = '   '*iOffset
      if oCat.expanded:
          sButton = '-'
      else:
          if oCat.tree_children:
              sButton = '+'
          else:
              sButton = '.'
      print("{0}{1}{2}".format(sOffset,sButton,oCat.name))
      if oCat.expanded:
          for oChild in oCat.tree_children:
              print_tree_info(oChild,iOffset+1)  
  </code></pre>
  
  <p>it printed </p>
  
  <pre><code>-ROOT_NODE
     +major1
     .base2
  </code></pre>
  
  <p>which is great.</p>
  
  <p>Now, passing the same node structure into the render function of a mako template (along with the mako template itself) I get the attribute error. </p>
  
  <p>Here's how I render the template:</p>
  
  <pre><code>template = Template(..........)
  html = template.render(category=root_node, item_template=template)
  </code></pre>
  
  <p>Here's the template</p>
  
  <pre><code>%if category is UNDEFINED:
  ERROR
  %elif category:
  &lt;div class="tree_item"  category_id="${category.id}"&gt;
  %if category.expanded:
      &lt;a class="collapse_tree_item"  category_id="${category.id}"&gt;-&lt;/a&gt;
  %elif category.tree_children:
      &lt;a class="expand_tree_item" category_id="${oCategory.id}"&gt;+&lt;/a&gt;
  %endif
  &lt;a class="select_tree_item"&gt;${category.name}&lt;/a&gt;
  %if category.expanded:
      %for oChild in category.tree_children:
            ${item_template.render(category=oChild,item_template=item_template)}
      %endfor
  %endif
  &lt;/div&gt;
  %endif
  </code></pre>