Richard Moon <richard@dcs.co.uk> 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 ) ?
Inside 'expr="..."', you are speaking Python, and the sequence variables, which have names which are illegal as Python identifiers, cannot be referenced directly. The correct syntax would be:: <dtml-in "_.string.split(tune_name,'|')"> <dtml-if sequence-start> <dtml-call expr="REQUEST.set('tune_name',_['sequence-item'])"> which uses the "_" variable representing the current namespace. An alternative is to use <dtml-let> to alias the sequence variables, like so:: <dtml-in "_.string.split(tune_name,'|')"> <dtml-let si=sequence-item> <dtml-if sequence-start> <dtml-call expr="REQUEST.set('tune_name',si)"> This oddness is an historical artefact: the sequence variables got their names long before DTML got the expr="" syntax. There is a proposal in the DTML wiki (look under http://www.zope.org/WikiCentral to find it) to add syntax to the <dtml-in> tag which will make all this unnecessary. Hope that helps, Tres. -- ========================================================= Tres Seaver tseaver@digicool.com tseaver@palladion.com