[Zope] Getting error assigning sequence-item to REQUEST
Jim Washington
jwashin@vt.edu
Fri, 14 Apr 2000 15:31:20 -0400
Hi, Richard
What you want is:
<dtml-call expr="REQUEST.set('tune_name',_['sequence-item'])">
but read further. There is another solution, too.
Anything you do in ""quotes within a DTML tag is interpreted as a
python expression.
The way you wrote it , zope tried to evaluate the expression
'sequence-item' as
"sequence minus item", and failed it because it could not find reference
to the variable 'sequence'.
One workaround is to gather the object from the '_' namespace.
_['avariable'] gets the first thing named avariable, so
_['sequence-item'] gets the current sequence-item, which is the above
"quickie" answer.
But what most of us do (sequence-item being a legacy in DTML from before
expressions were allowed IIRC, so it would break a lot of existing code
to rename it) is use a 'dtml-let' tag immediately after the 'dtml-in'
tag.
e.g.,
<dtml-in "_.string.split(tune_names,'|'")>
<dtml-let currenttune=sequence-item>
...do something with currenttune...
</dtml-let>
</dtml-in>
Using a 'dtml-let' allows you to use exactly the same syntax that you
really wanted to use before, but now you have a handle to the thing you
are working with, and it is evaluated as what you want, not a
subtraction.
hth.
-- Jim Washington
Richard Moon wrote:
>
> Can anyone tell me why the following
> <dtml-in "_.string.split(tune_name,'|')">
> <dtml-if sequence-start>
> <dtml-call expr="REQUEST.set('tune_name',sequence-item)">
>
> raises the error "Error Type: Name Error Error Value:sequence"
>
> It is the last line which raises the error.
>
> This is the error I would expect if I was trying to use a variable which
> wasn't in the current namespace so I am confused why I cannot use
> sequence-item in this way.
>
> Can anyone tell me the correct syntax (and why ) ?
>
> Thanks in advance
>
> Richard
>
> Richard Moon
> richard@dcs.co.uk