[Zope] why is this?
Jim Washington
jwashin@vt.edu
Wed, 07 Mar 2001 14:41:01 -0500
You might want to look into Python Scripts (or Python Methods). They
provide a really good place for string manipulation and business logic.
You can make routines that you can call from DTML, letting you use each
as it is advantageous to you.
-- Jim Washington
Joh Johannsen wrote:
>
> Siggy Brentrup wrote:
> >
> > Joh Johannsen <jojo@farm9.com> writes:
> >
> > > This works:
> > >
> > > <dtml-call "REQUEST.set('asplit',_.string.split(bigstring,'&'))">
> > > <dtml-call "REQUEST.set('aname',asplit[0])">
> > > <dtml-var aname>
> > >
> > > But this doesn't:
> > >
> > > <dtml-call "REQUEST.set('asplit',_.string.split(bigstring,'&'))">
> > > <dtml-var asplit[0]>
> > >
> > > Why is that? What does work for list access?
> >
> > It's fundamental dtml,
> >
> > <dtml-var aname> is a shorthand for <dtml-var name="aname">
> > <dtml-val "asplit[0]'> is a shorthand for <dtml-var expr="asplit[0]">
> >
> > you were trying to use an expression where a name was expected.
> >
> >
> yes, thanks.
>
> Not being aware of the shorthand notation, I just assumed it was Python,
> where you can refer to variables and list members without quotes.
>
> This "almost-Python" approach seems to confuse alot of people. What I'd
> really like to do with the above example is just directly embed Python:
>
> <dtml-let asplit=string.split(bigstring,'&')>
> <dtml-var asplit[0]>
>
> Isn't that a bit more straightforward than:
>
> <dtml-call "REQUEST.set('asplit',_.string.split(bigstring,'&'))">
> <dtml-var "asplit[0]">
>
> This second one requires knowing:
>
> 1. REQUEST.set (and no doubt there are alternatives for setting a
> variable which I'm not aware of)
> 2. enclosing REQUEST.set in quotes
> 3. single quoting variable name as the first parameter to REQUEST.set
> 4. NOT quoting second parameter to REQUEST.set
> 5. using "_." before any namespace reference (sometimes, not exactly
> sure when) in the second parameter to REQUEST.set
> 6. quoting the list reference (as opposed to NOT quoting a variable
> reference)
>
> It seems like python-Zope integration could be alot more transparent.