[Zope] DTML source

Dennis Nichols nichols@tradingconnections.com
Thu, 23 Nov 2000 09:21:36 -0600


At 11/23/00 01:38 PM, Tom Deprez wrote:
>Are there some sites which publish there DTML source(structure)? I'm
>particulary looking on how several navigation, menu, ... structures are
>implemented in Zope.

I use the following DTML Method (probably shouldn't be done in dtml) to 
produce a vertical, indented menu where folders are expanded to subfolders 
only if you're in one of the subfolders. Three custom folders are used to 
build the site (Category-Top, Category-Middle, and Category-Bottom). Each 
folder has a menu_entry property. A folder appears in the menu only if its 
menu_entry is non-blank. If you are currently in Pop Culture/Reviews/Books, 
the menu looks like this:

Ask the Experts
College
Pop Culture
    Quiz
    Reviews
       Books
       Movies
       Music
    Trends
Sports

Here's the dtml. It's called display_menu and is recursive. Replace 
home_id_here with the id of the site's base folder. The base folder does 
not appear in the menu display.

  <dtml-unless topdown>
    <dtml-call "REQUEST.set('topdown',[])">
    <dtml-call "REQUEST.set('homefound','n')">
    <dtml-in PARENTS skip_unauthorized>
      <dtml-if "homefound == 'n'">
        <dtml-call "topdown.insert(0, _['sequence-item'])">
        <dtml-if "_['sequence-item'].id == 'home_id_here'">
          <dtml-call "REQUEST.set('homefound', 'y')">
        </dtml-if>
      </dtml-if>
    </dtml-in>
    <dtml-call "REQUEST.set('level', 0)">
    <dtml-call "REQUEST.set('NodeToShow', topdown[0])">
  </dtml-unless>
  <dtml-if "level > 0">
    <dtml-with NodeToShow>
      <dtml-var "'&nbsp;'*3*(_.int(level)-1)">
      <a href="&dtml-absolute_url;" class=toolbox>&dtml-menu_entry;</a><br>
    </dtml-with>
  </dtml-if>
  <dtml-if "level < _.len(topdown) and NodeToShow.id == topdown[level].id">
    <dtml-in 
"NodeToShow.objectValues(['Category-Top','Category-Middle','Category-Bottom'])"
             sort=id skip_unauthorized>
      <dtml-if "_['sequence-item'].menu_entry">
        <dtml-call "REQUEST.set('level', level+1)">
        <dtml-call "REQUEST.set('NodeToShow', _['sequence-item'])">
        <dtml-var display_menu>
        <dtml-call "REQUEST.set('level', level-1)">
      </dtml-if>
    </dtml-in>
  </dtml-if>

Not my finest piece of coding, but maybe it will help.

--
Dennis Nichols
nichols@tradingconnections.com