[Zope] How do I call DTML Method which name is stored in a variable

David Kankiewicz kankie@thegrid.net
Fri, 10 Dec 1999 11:32:40 -0800


the simple anwser for Carlos Henrique Bauer,

<dtml-var "_[variable]">



I was doing to post this pure DTML response to "String to object ID" (it
was not too complex... 3 lines, no count </dtml-..>), but I ran into a
nice triple checking the path length because of DTML's 'with' construct.
(same deal with direct addressing). Know I'm wonder why it can't be
fixed, why can't <dtml-var "_['folder.subfolder']._['object'].id"> just
work????  I looked at the source code, AFAIK its only the security '_'
that stops it. (I'm no expert!)



Summery: a single path level, i.e. no periods in the name "myfolder"
used in 'dtml-with' needs to be fetched with

"_['string_without_dots_in_it']"  or  "_.getitem('string',flag)"
flag defaults to 0, which does not call a callable object. set to 1 if
you want it to call them.


Where as a string with periods "myfolder.subfolder.stuff" needs:
"'string.with.dots.in.it'" or e.g. <dtml-with
"_.string.join(path_with_object[:-1],'.')">

The last check in the triple was if the path is only the object... no
path.



OK an example:

I can use this to access objects from a Catalog search, as long as I
know it doesn't have the above problem with DTML addressing...

(you could replace getpath(stuff) with a absolute_url splitter to make
it even more complex)

<dtml-let
path_with_object="_.string.split(getpath(data_record_id_)[1:],'/')">
<dtml-with "_.string.join(path_with_object[:-1],'.')">
<dtml-var "_[path_with_object[-1]].id"></dtml-with></dtml-let>



   The above is faster than getobject(data_record_id_,REQUEST) by ~40%
:')  its fast I like it. :)


Having fun with DTML ;)

David,
tone..