Breadcrumb Style Navigation
| Status: | Contributed |
|---|
There are various ways of implementing breadcrumb style navigation in TurboGears.
This example shows how to implement bread crumb style navigation using introspection. This can be done using cherrypy._cputil.get_object_trail().
Using CherryPy Introspection
controller.py:
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 crumbsThen, import the function and create your navigation bar in your template:
<div id="navbar">
<span py:for="href in createNavBarLinks()">
<a class="menu" href="${href[0]}">${href[1]}</a>
</span>
</div>A derivative of this solution can be found at http://code.google.com/p/tg-breadcrumbs/
The comment feature has been disabled on this page due to heavy
spamming. If you want to comment on the contents of this page, if you have
questions, or want to report an error, please write to the TurboGears
mailing list.