tags:

views:

68

answers:

2

In the main kid template file, I want it to have only div tags, each of which do only call a rendered kid file and paste content inside it. (like "include" function in php) but I don't know how to do this. Does someone have any ideas about it?

+1  A: 

If you swap to genshi instead of the default kid you can do this with an include tag:

 <xi:include href="menu.html" />

Swapping to genshi is fairly easy, I think its a matter of confuration only. The templates tags works otherwise the same. You should rename the extensions from .kid to .html though.

Stefan Lundström
This is correct genshi defers only in 2 tags and is faster, compiles to better syntax and on top of that gives better error output.
Jorge Vargas
+1  A: 

You can first define a "base_layout.kid" template:

<html xmlns:py="http://purl.org/kid/ns#"&gt;
    <head>
        <title>App Name - ${page_title}</title>
        <link href="layout.css" type="text/css" rel="stylesheet" />
        ${page_specific_css()}
    </head>

    <body>
        <h1>Now viewing: ${page_title} of App Name</h1>

        <content>Default content</content>

        <div class="footer">Page Footer Text</div>
    </body>

</html>

Then replace the "content" tag in "page.kid" with whatever data you want:

<html py:layout="'base_layout.kid'"
  xmlns:py="http://purl.org/kid/ns#"&gt;

    <link py:def="page_specific_css()"
    href="layout.css" type="text/css" rel="stylesheet" />

    <div py:match="item.tag == 'content'">
        <ul>
             <li>Content Item 1</li>
             <li>Content Item 2</li>
             <li>Content Item 3</li>
        </ul>
    </div>

</html>

You can check whether you get the correct html in python shell (after removing all the identifiers used):

>>> import kid
>>> t = kid.Template("page.kid")
>>> print t.serialize()
Sushant