[Zope] Simple Breadcrumbs in ZPT
    Troy Farrell 
    troy at entheossoft.com
       
    Thu Mar 18 00:15:06 EST 2004
    
    
  
Zopelabs.com is normally the place to look for code snippets.
I put these in my site root and use them for almost every site I host.  The page 
template I call 'you_are_here' and the python script 'breadcrumbs'.  I probably 
stole these from something.  Mebbe from early CMF (?)
Page Template:
<div class="breadcrumbs" style="text-align:left;">
you are here:
   <span tal:repeat="crumb here/breadcrumbs">
     <a tal:attributes="href string:${crumb/absolute_url}/;
                        title crumb/title;"
        tal:content="crumb/title_or_id">home</a>
     <span 
tal:condition="not:repeat/crumb/end"> <strong>»</strong> </span>
   </span>
</div>
Python Script:
## Script (Python) "breadcrumbs"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
root = ('',)
breadcrumbs = []
request = context.REQUEST
vRoot = request.has_key('VirtualRootPhysicalPath')
# Subtle bug fixed below.
# PARENTS is a list.  We must work on a copy because
# we call reverse() on it.  Previously, we were reversing
# the PARENTS list, making us unable to call this script
# twice for a given HTTP REQUEST
PARENTS = context.REQUEST.PARENTS[:]
foldertypes = ('Folder','Photo Folder')
PARENTS.reverse()
if vRoot:
     root = request.VirtualRootPhysicalPath #inside if block
     PARENTS = PARENTS[len(root)-1:] #inside if block
for crumb in PARENTS:
     if crumb.meta_type in foldertypes: breadcrumbs.append(crumb) #inside for block
     else: return breadcrumbs  #inside for block
return breadcrumbs
##### END Python Script #####
Troy
-- 
And the glory of the LORD shall be revealed, and all flesh shall see it 
together: for the mouth of the LORD hath spoken it.
Isaiah 40.5
Michael Fox wrote:
> Hi *,
> 
> Can someone please point me in the right direction here.
> 
> I'm looking for a simple python/zpt snippet to do breadcrumbs in my
> master page template.
    
    
More information about the Zope
mailing list