I wrote a widget to display a navigation "portlet" (which is just a
widget but I call them portlets when they are for use in sidebars).

If you pass in a page object (which has childpage and path
properties), it displays everything from the homepage to the current
page in nested lists and all the sibling pages of each of those pages.

I had to create a class function that checks identity, because when I tried:
py:attrs="href=node.stub, class=(node is path[-1]) and 'activepage'" I
got an error in Kid.

Anyway, code for NavPortlet and a Sitemap portlet that I just knocked
up (and is therefor untested) follows:

class NavPortlet(Widget):
    params = ["page"]

    template = """
    <div class="nav portlet" xmlns:py="http://purl.org/kid/ns#";>
        <li py:def="display_node(node, path)">
            <a href=""
               py:content="node.title"
               py:attrs="href=node.stub, class=node.is_(path[-1]) and
'activepage'">Page Title</a>
            <ul py:if="len(path)>1 and node is path[1]">
                <li py:for="child_page in node.child_pages"
                    py:replace="display_node(child_page, path[1:])">
                </li>
            </ul>
        </li>
        <ul>
            <li py:for="child_page in page.path[0].child_pages"
                py:replace="display_node(child_page, page.path)">
                Test
            </li>
        </ul>
    </div>
    """

class SitemapPortlet(Widget):
    params = ["page"]

    template = """
    <div class="nav portlet" xmlns:py="http://purl.org/kid/ns#";>
        <li py:def="display_node(node)">
            <a href=""
               py:content="node.title"
               py:attrs="href=node.stub">Page Title</a>
            <ul py:if="node.child_pages">
                <li py:for="child_page in node.child_pages"
                    py:replace="display_node(child_page)">
                </li>
            </ul>
        </li>
        <ul>
            <li py:for="child_page in page.child_pages"
                py:replace="display_node(child_page)">
            </li>
        </ul>
    </div>
    """


On 6/3/06, Collin L <[EMAIL PROTECTED]> wrote:
>
> Hi,
> I have a SQLObject that has a foreign key to itself to support a nested
> structure (like a file system).  I want to output this nested structure
> with ul's and li's in the Kid templating language.  Kid has loops, but
> not recursion.  I was thinking I could just write a py function to do
> this, but I'm not sure how to call the function from the template in a
> way that outputs the html.
>
> def printgroups(rootgroups):
>     output = ''
>     for group in rootgroups:
>         output = output + '<ul>'
>         printgroups(group.groups)
>         output = output + '</ul>'
>
>     return output
>
>
> Any ideas?
>
> Thanks,
> Collin
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to