dynamic navigation menu: comparing context to container
Hi, I have a Python script called select_this() that is supposed to return a boolean indicating whether the current item should be highlighted or not, depending on whether the current context is on that item's path. (One problem I may have in asking my question is I may not be using the correct terminology, so I invite any rewording that would make this more clear. I'm relatively new to Zope.) The problem is that it always returns 0 (False), so I think my problem is that I don't understand what context and container are--or how to compare them. Here's what the script looks like: # Return boolean indicating whether the specified item should be # displayed as selected. current = context while 1: if current == container: break if item == current: return 1 current = current.getParentNode() return 0 Here's the snippet of a ZPT page template where I'm trying to use select_this() to build the top-level of a dynamic navigation menu using the OrderedFolder objects within a content OrderedFolder: <span tal:omit-tag="" tal:repeat="section python:container.content.objectValues(['Ordered Folder'])"> <td tal:attributes="class python:test(container.select_this(section), 'tab_select', 'tab_unselect')" width="120" height="24"> <a tal:content="section/title_or_id" tal:attributes="href python:'/%s/content/%s' % (container.getId(), section.getId())" class="tab"></a> </td> </span> The structure of the site looks like this: /Root /navtest (Folder) /content (OrderedFolder) /a (OrderedFolder) /b (OrderedFolder) /c (OrderedFolder) select_this (Python Script) No matter where I navigate, all three top-level folders are shown with the style tab_unselect. If I navigate to, e.g., http://localhost:8080/navtest/content/a/ I expect that navigation item to have the class tab_select. I appreciate any and all feedback and help. Thanks, // mark
[I wrote]
Here's what the script looks like:
# Return boolean indicating whether the specified item should be # displayed as selected.
current = context
while 1: if current == container: break if item == current: return 1 current = current.getParentNode()
return 0
[snip] I think the reason current (i.e., context) is equal to container is the fact that the script is stored in the container. So with this kind of structure: /Root/ navtest/ select_this content/ a/ even though I navigate explicitly to a, since the ZPT macros are in navtest and so is select_this, the context is navtest. Hmm, how do I get the intended context? // mark
participants (1)
-
Mark McEahern