[ZPT] dynamic navigation menus

Mark McEahern marklists@mceahern.com
Thu, 1 Aug 2002 11:09:19 -0500


> As was already mentioned, the OrderedFolder product works very well for
> this. I seem to recall, however, it uses code that is not yet fully
> debugged/working on Windows. I'm not sure if that's still an issue or not.
> http://www.zope.org/Members/srichter/Products/OrderedFolder

Yes, that version didn't work on Windows XP.  I found a more recent version
here that does:

  http://demo.iuveno-net.de/iuveno/Products/OrderedFolder

It's confusing--are these the same thing?  Why isn't the more recent version
linked to from the zope.org page?

> If OrderedFolder doesn't work, then adding a "sort_order" property to your
> content folders should work.

Thankfully, OrderedFolder works dandy.  I'd hate to have to explain to the
users all the rigamorale that would have been required to move item 9 into
position 3, fer instance.  ;-)  With OrderedFolder I can just tell them to
click away at the arrows until it looks right.

> A python script should be able to determine the current section and
> subsection. Then a tal:condition could be used to determine whether to
> output 'selected' or 'unselected' css/html tags.

Here's the script I'm currently using:

  # Function name: select_this
  # Parameters: item
  #
  # Return boolean indicating whether the specified item should be
  # displayed as selected.

  current = context

  while 1:
    # FIXME: No matter where this is called from, current is
    # always "equal to" container.
    if current == container:
      break
    if item == current:
      return 1
    current = current.getParentNode()

  return 0

The idea behind it is that I iterate over the content folders and for each
item, I call this select_this() function.  No matter where I happen to call
it, it returns 0/False because my first test:

  if current == container:

is always True.  How do I compare the context to the container?  With "is"?
I tried that and I get the same results.

Here's the snippet where I call select_this():

    <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>

// mark

-