[ZPT] dynamic navigation menus

Mark McEahern marklists@mceahern.com
Wed, 31 Jul 2002 11:07:53 -0500


> From: Chris Withers [mailto:chrisw@nipltd.com]
[snip]
> The rest, well, I'm afraid I didn't have tiem to read your whole
> post, any chance you could ask seperate, smaller questions?

I'll try...

One of my goals with the dynamic navigation is to distinguish selected from
unselected menu choices.

I have this kind of structure:

  /Root
    /navtest
      index_html (Page Template)
      master_html (Page Template)
      select_this (Script)
      /content
        /a
          /a_1
          /a_2
        /b
        /c

Everything that isn't a Page Template or Script is a Folder.

Suppose the user navigates to section a; e.g.,

  http://localhost:8080/navtest/a/

Since that folder doesn't have an index_html, Acquisition means the user
will get the one in navtest.  This page, in turn, just uses the whole page
macro defined in master_html:

  <html metal:use-macro="container/master_html/macros/page">
  </html>

The relevant snippet from there that renders the top-level tabbed navigation
looks like this:

   <tr>
    <span tal:omit-tag=""
          tal:repeat="section container/content/objectValues">
    <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:'content/%s' % (section.getId())"
         class="tab"></a>
    </td>
    </span>
    <td width="24">&nbsp;</td>
  </tr>

The select_this() function looks like this:

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

  current = context

  while current != container:
    if item == current:
      return 1
    current = current.getParentNode()

  return 0

However, when the page is rendered and I click on section a, that tab
doesn't not have the class="tab_select" style, but the "tab_unselect" style.

I'm not sure what I'm doing wrong.  I've been using Python for over a year,
but I'm relatively new to Zope and brand new to ZPT, so I'm sure I'm making
some conceptual mistakes.

I'll continue trying to reclarify my question as I learn more.

Thanks,

// mark

-