[Zope] dtml-with & misbehaving strings
Jim Fulton
jim@digicool.com
Tue, 01 Feb 2000 14:43:20 -0500
Thomas wrote:
>
> Hi everyone,
>
> I have a folder with a property. In a method within this folder I try the
> following:
>
> <dtml-with "_[myproperty]">
> grab some stuff
> </dtml-with>
>
> where myproperty is a string equal to Games.Whatup
>
> Both 'Games' and 'Whatup' are objects. So I am trying to
> drill down my directory and stack the namespace via the with
> tag, but I get the following message:
>
> Error Type: KeyError
> Error Value: Games.Whatup
>
> I want it to to do the following (which works fine):
>
> <dtml-with "Games.Whatup">
> grab some stuff
> </dtml-with>
>
> Am i missing something here? Thanks for any help and hints in advance.
Yup. The namespace lookup expression: "_[name]" takes a single
name, but you have given it a string containing two names.
I suggest that "Games.Whatup" is really a path expression.
(Note that dots are legal in Zope names and therefore not
a good choice for path separators, but that's beside the point.)
There isn't a general way, in DTML currently to take a string
containing a path and convert it two an object. (If there was,
it would use '/'s as path sperators, as in "Games/Whatup".)
Now, suppose your property was defined with "lines" or "tokens",
which is a list of strings, and that you know that it always
contained a two-part path, then you could use something like:
<dtml-with "_.getattr(_[myproperty[0]], myproperty[1])">
This gets the name from the namespace corresponding to the first
element if myproperty and then gets an attribute from the resulting
object using the second element.
Hope this helps.
Jim
--
Jim Fulton mailto:jim@digicool.com
Technical Director (888) 344-4332 Python Powered!
Digital Creations http://www.digicool.com http://www.python.org
Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission. Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.