[Zope] 'Cookie crumb trail' navigation
Mike Renfro
renfro@tntech.edu
Fri, 22 Mar 2002 18:11:43 -0600
On Fri, Mar 22, 2002 at 03:19:28PM -0800, Iago wrote:
> Here's the code for recursiveLinks:
You'll drive yourself insane mixing logic ("how do I get a list of my
parent folders to build a breadcrumb trail?") and presentation ("I
want each element of my breadcrumb trail to be hotlinked, with '>'
characters between each one").
That having been said, I have a snippet of code at my Python/ZPT
sitemap example (http://www.zope.org/Members/mwr/python_zpt_sitemap)
that generates a list of folders similar to what you want:
###
### list_parent_folders
###
results=[]
# Find parent folders from the current folder
ids2=[]
for id in context.REQUEST.PARENTS[:-1]:
ids2.append(id.id)
ids2.reverse()
for id in ids2:
object=getattr(context,id)
if hasattr(object.aq_explicit,'menu_entry'):
results.append(object)
return results
The script does check for the existence of a 'menu_entry' property on
each container, but you could remove that check if you want.
ZPT that should accomplish the breadcrumbs might look like (completely
untested, but built off of my known-working example):
<div id="breadcrumbs"
tal:define="sequence python:here.list_parent_folders()">
<tal:block repeat="item sequence">
<span class="crumb"
tal:condition="python:here!=item or template.id!='index_html'">
<a href="link url"
tal:attributes="href item/absolute_url"
tal:content="item/title_or_id">link to some folder</a> --
</span>
<span class="crumb"
tal:condition="python:here==item and template.id=='index_html'">
<strong><span tal:replace="item/title_or_id">current folder (not linked)</span></strong>
</span>
</tal:block>
</div>
And I think that'll give you a breadcrumb trail that looks like:
<a href="/a">Title A</a> -- <a href="/a/b">Title B</a> -- <strong>Title C</strong>
if you were in the folder /a/b/c
Hope that works, or that you can use it as a starting point.
--
Mike Renfro / R&D Engineer, Center for Manufacturing Research,
931 372-3601 / Tennessee Technological University -- renfro@tntech.edu