[Zope] referencing title value as a var name

Casey Duncan cduncan@kaivo.com
Mon, 13 Aug 2001 09:57:51 -0600


Hamzat kamal wrote:
> 
> Goodday,
> 
> My first question is that is it possible to store the title value of an
> object with <dtml-let> and later reference it  with <dtml-if > in another
> object?
> if it is possible, pls furnish me with the deatils. Else i think i better
> explain what i actually have in mind.
> 
> What i wanted is to list the titles of all the dtml documents in a folder,
> set the hyperlink of each dtml document to its id and finally store the
> value of the clicked title in a variable name. I think I am able to scale
> through this, but my problem now is to reference that variable name in
> another object.
> 
> Below is the code i used to iterate and store the title value; this code is
> on one object called content_html:
> 
> <ul>
> <dtml-in "objectValues(['DTML Document'])" sort=title>
> <li>
> <a href="&dtml-id;/">&dtml-title;
> <dtml-let dname="_['sequence-var-title']">
> </dtml-let>
> </a>
> </li>
> </dtml-in>
> </ul>
> 
> Below here is where i am having a problem, the code here is on another
> object called index_html but both content_html and index_html are in the
> same folder.
> 
> <dtml-let dday=dname>
> <dtml-if expr="dday[0:6]=='Saturd'">
> <dtml-var saturday2>
> <dtml-elif expr="dday[0:6]=='Friday'">
> <dtml-var friday2>
> <dtml-elif expr="dday[0:6]=='Sunday'">
> <dtml-var sunday2>
> <dtml-else>
> <dtml-var table2>
> </dtml-if>
> </dtml-let>
> 
> Help in any form will be highly appreciated.
> 
> Thanks.
> 
> kamal.
> 

Anything you put inside a DTML let (including other object calls by
name) have access to the name. However, I'm not convinced that you even
need it to be this complex. From what I see, the first word of the title
is a day, and based on that day value, you want to call another
method/object. What I would do is get the first word of the title and
try to call an object by that name (You'll need to create 7 objects:
Monday, Tuesday, Wednesday... etc), and failing that call the table2
object. Like so:

<dtml-in expr="objectValues('DTML Document')" sort="title">
  <li>
  <a href="&dtml-id;/">&dtml-title;
  <dtml-let day="_.string.split(title)[0]">
    <dtml-try>
      <dtml-var expr="_[day]">
    <dtml-except NameError KeyError>
      <dtml-var name="table2">
    </dtml-try>
  </dtml-let>
  </a>
  </li>
</dtml-in>

This avoids all those if/elifs. The key is _[day] which looks up the
object whose name is the value of the variable day, which is set to the
first word of the title using string.split (which splits a string on
whitespace into a list) and retreiving the first item of the list.

hth,
-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>