[Zope] referencing title value as a var name

Kerekes Lajos lkerekes@xperts.hu
Tue, 14 Aug 2001 11:37:21 +0200


Casey Duncan wrote:

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

Hi!

I have same problem. Could you help me?
This is the source:

<dtml-in SelectState size=10 start=query_start>
<dtml-var expr="_['STATE']">
</dtml-in>

SelectState is a ZSQL method, gives the STATE,
STATE is an integer, and there are three DTML
DOCUMENT (named 0, 1, 2) in the folder,  and these
objects contains the "state string" (for example "OK",
"Connection error" etc.)

If I use the code above, I get only 0, 1 or 2, not the
state strings.

I tried <dtml-var expr="_[STATE]"> too, but it gives
these erorrs.
Error Type: SystemError
Error Value: bad argument to internal function

   Thank you:

    Lajos  Kerekes