Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 4 (modified by bjourne, 13 years ago) (diff)

link to page showing it

This example shows how to implement bread crumb style navigation using introspection. I like this navigation style and I wanted to implement it using the structure I defined in my controllers. A hint on the mailing list (thanks Elvelind Grandin) showed me this can be done using cherrypy._cputil.get_object_trail().

I wrote this with SVN revision 800.

def createNavBarLinks():
    """Return link information for constructing bread crumb navigation.

    cherry_trail = cherrypy._cputil.get_object_trail()
    href = '/'
    crumbs = [(href, 'home')] 
    for item in cherry_trail:
        # item[0] is the name you use in the URL to access the controller.
        # item[1] is the actual controller
        if isinstance(item[1], (Controller, BaseDataController)):
            if item[0] != 'root':
                href = "%s%s/" % (href, item[0])
                crumbs.append([href, item[0]])
    return crumbs

Now in your kid templte, import the function and create your navigation bar.

        <div id="navbar">
            <span py:for="href in createNavBarLinks()">
                <a class="menu" href="${href[0]}">${href[1]}</a>

More info about breadcrumb navigation: