Simple Breadcrumbs in ZPT
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. Regards, Michael Fox ^-^ Analyst/Programmer <`-`> ___ Century Software ' `' '. Tel +61 2 9460 1422 `. ` ' .'. Fax +61 2 9460 3098 ||.' '._/'.`.' www.CenturySoftware.com.au "" "
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.
Troy Farrell wrote:
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 (?)
Ohh... What simple in DTML! <dtml-call "REQUEST.set('rev', [])"> <dtml-in "PARENTS[:-4]" skip_unauthorized> <dtml-let item=sequence-item> <dtml-call "rev.insert(0, item)"> </dtml-let> </dtml-in> <dtml-in rev> <dtml-with sequence-item> <a href="<dtml-var absolute_url>"><dtml-var title_or_id></a> </dtml-with> <dtml-unless sequence-end> > </dtml-unless> </dtml-in> Regards J. Lukesh
Jaroslav Lukesh wrote:
Troy Farrell wrote:
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 (?)
Ohh... What simple in DTML!
Huh? What does DTML buy you here? You're jus tusing parents, which is crummy... Why the skip unauthorized? Why the -4 slice? Still, if you really wanted to use parents: <tal:i define="parents request/PARENTS" repeat="i range(len(parents)-4,0,-1)"> <a tal:define="item parents/?i" tal:attributes="href item/absolute_url" tal:content="item/title_or_id"/> <tal:c condition="not:repeat/i/end"> > </tal:c> </tal:i> cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (4)
-
Chris Withers -
Jaroslav Lukesh -
Michael Fox -
Troy Farrell