Great!

Christoph you solved my problem even if I don't exactly know why ;) It seems that the template gets lost somewhere, therefore I added a small cache for it and ... it works. But that's ok for me 'cause I will add some caching anyways to my app.

See the attached example.

Thanks a lot for your help!
Dirk

Christoph Zwerschke schrieb:
Dirk Holtwick wrote:
Do you have an idea why the example fails and how I could solve this
problem? I have the impression that Kid is focused more on files than
on strings? Help is very appreciated.

I tested a little bit and I think the reason is that load_template is not reentrant or something. It works if you do it like that:

-------------

master = """\
<html xmlns:py="http://purl.org/kid/ns#";>
     <body py:match="item.tag == 'body'">
         <p>my header</p>
         <div py:replace="item[:]" />
         <p>my footer</p>
     </body>
</html>"""

page = """\
<html py:extends="master" xmlns:py="http://purl.org/kid/ns#";>
     <body>
         <p>my content</p>
     </body>
</html>"""

class KidTemplateManager:

     def __init__(self, master):
         self.master = None
         self.master = self.load(master)

     def load(self, source):
         import kid
         return kid.load_template(source, cache=False,
             ns=dict(master=self.master))

template = KidTemplateManager(master).load(page)

print template.serialize()

-------------

I'd like to make a ticket of this to investigate further, but the trac is still broken and I still can't log in (@David: hint, hint!).

-- Christoph


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
kid-template-discuss mailing list
kid-template-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kid-template-discuss
master = """\
<html xmlns:py="http://purl.org/kid/ns#";>
    <body py:match="item.tag == 'body'">
        <p>my header</p>
        <div py:replace="item[:]" />
        <p>my footer</p>
    </body>
</html>"""

page = """\
<html py:extends="manager.load(page)" xmlns:py="http://purl.org/kid/ns#";>
    <body>
        <p>my content</p>
    </body>
</html>"""

class KidTemplateManager:

    def __init__(self):
        self.pool = []

    def load(self, source):
        import kid
        template = kid.load_template(
            source,
            cache=False,
            ns=dict(manager=self, page=master))
        self.pool.append(template)
        return template

template = KidTemplateManager().load(page)
print template.serialize()
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
kid-template-discuss mailing list
kid-template-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kid-template-discuss

Reply via email to