Howdy. I'll get right to it: Say I have a folder structure, a/b/c I'm in c. I want to establish some kind of method (my current attempts are a python script), stored in a, which will render the following: <a href="http://myserver.org/a/">A</a>: <a href="http://myserver.org/a/b/">B</a>: <b>C</b>: My current attempt only gets me: <a href="http://myserver.org/a/">A</a>: <b>C</b>: Here's the code for recursiveLinks: --- SNIP --- import string if list == None: list = [] if len(list) > 0: list.append( '<a href="%s">%s</a>' % ( context.absolute_url(), context.title or context.id ) ) else: list.append( '<b>%s</b>' % context.title or context.id ) if context is container: list.reverse() print string.join(list,' > ') return printed else: # this doesn't work: return context['..'].recursiveLinks(list=list) return container.recursiveLinks(list=list) --- SNIP --- Now, what I _really_ want is for 'context' to give me an object which is 'the context one level up from here', so I can recursively step up until i hit a folder I somehow designate as "top". I thought I was getting that with context and container, but as it turns out, container, where the above python script (recursiveLinks) lives, is not the container of context (the 'c' folder in this case) -- it's the container of the script (near as I can tell, since the result I'm getting is A: C and not A: B: C) How can I get 'next-folder-up' from this, in an object context so that I can grab the 'title' and other attributes off of the object, and recurse (as I thought I was doing above) by going to yet another 'next-folder-up'? Any help here's appreciated. I'm about 48 hours into learning zope. :) -- Fred Hicks <iago@iago.net>
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
http://www.zopelabs.com/cookbook/990688377 ----- Original Message ----- From: "Iago" <iago@iago.net> To: <zope@zope.org> Sent: Friday, March 22, 2002 3:19 PM Subject: [Zope] 'Cookie crumb trail' navigation
Howdy. I'll get right to it:
Say I have a folder structure, a/b/c
I'm in c. I want to establish some kind of method (my current attempts are a python script), stored in a, which will render the following:
<a href="http://myserver.org/a/">A</a>: <a href="http://myserver.org/a/b/">B</a>: <b>C</b>:
My current attempt only gets me:
<a href="http://myserver.org/a/">A</a>: <b>C</b>:
Here's the code for recursiveLinks:
--- SNIP ---
import string
if list == None: list = []
if len(list) > 0: list.append( '<a href="%s">%s</a>' % ( context.absolute_url(), context.title or context.id ) ) else: list.append( '<b>%s</b>' % context.title or context.id )
if context is container: list.reverse() print string.join(list,' > ') return printed else: # this doesn't work: return context['..'].recursiveLinks(list=list) return container.recursiveLinks(list=list)
--- SNIP ---
Now, what I _really_ want is for 'context' to give me an object which is 'the context one level up from here', so I can recursively step up until i hit a folder I somehow designate as "top". I thought I was getting that with context and container, but as it turns out, container, where the above python script (recursiveLinks) lives, is not the container of context (the 'c' folder in this case) -- it's the container of the script (near as I can tell, since the result I'm getting is A: C and not A: B: C)
How can I get 'next-folder-up' from this, in an object context so that I can grab the 'title' and other attributes off of the object, and recurse (as I thought I was doing above) by going to yet another 'next-folder-up'?
Any help here's appreciated. I'm about 48 hours into learning zope. :)
-- Fred Hicks <iago@iago.net>
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Iago writes:
Say I have a folder structure, a/b/c
I'm in c. I want to establish some kind of method (my current attempts are a python script), stored in a, which will render the following:
<a href="http://myserver.org/a/">A</a>: <a href="http://myserver.org/a/b/">B</a>: <b>C</b>: Look at the "breadcrumbs" script which is part of Zope CMFDefault (part of CMF 1.2).
Alternatively, you can search the mailing list archives for "breadcrumbs". Dieter
participants (4)
-
Andy McKay -
Dieter Maurer -
Iago -
Mike Renfro