Hi all,

I have been using kid templates for a few months now, and am impressed
with the templating system so far.

However I  have a need to display a tree structure in a series of
nested html lists, which currently I am doing by decorating the tree
in the python code, and inserting into the template using the XML()
function.

Clearly it would be far nicer and more in the spirit of the templating
system if I  could do the recursion over the tree in the template. I
tried the following code as a minimal example which fails
spectacularly:

# tree.py
from kid import Template

class Node (object):
    def __init__(self, name, children=[]):
        self.children = children
        self.name = name

top = Node("top")
a = Node("A", [Node("a")])
b = Node("B", [Node("x")])
top.children = [a, b]

template = Template(name="recurse")
template.tree = top
print template.serialize(output='html')

# recurse.kid
<html xmlns:py="http://purl.org/kid/ns#";>
   <body>
      <ul py:def="display_tree(tree)">
         <li>
         ${tree.name}
         <div py:for="node in tree.children" py:replace="display_tree(node)" />
         </li>
      </ul>

      <div py:replace="display_tree(tree)">
         Key/Value Table replaces this text
      </div>

   </body>
</html>
#====================================================

What the effect of this code is, is to create an infinite (well, 1000
level...) recursion before bombing out.

So what seems to be happening is that the template expansion is
happening at compile time of the template, rather than as I had
expected creating a function that could be used to recurse at runtime.
Is there a workaround for this? Is it on the list of bugs? Is it worth
me looking at a fix for this and submitting a patch?

Thanks,

--
Ant...


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
kid-template-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/kid-template-discuss

Reply via email to