[Zope] Getting an object from it's id

Ivan Cornell ivan.cornell@framestore.co.uk
Tue, 23 Jan 2001 13:20:41 +0000


Geoff Armstrong wrote:

> What I'm trying to do here is avoid using <dtml-in, since in order for it to
> put the object in the namespace it has to iterate over all of them (there
> could be any number).
>
> All I have at the beginning is the name of the object in the REQUEST part of
> the namespace as picked up from a form. My method is the action to that
> form.
>
> In DTML there doesn't seem to be a way of saying, "I have this string with
> the name of an object, now fetch me the object."
>

Hi Geoff,

Try using _.getitem(), as in:
<dtml-let myObject="_.getitem(myId)">
... <dtml-call myObject.foo> ...
</dtml-let>
or probably:
<dtml-let myObject="_.getitem(REQUEST['myId'])">

If you aren't sure of the existance of the object, wrap the above in:
<dtml-if "_.hasattr(this(), REQUEST['myId'])">
</dtml-if>

Ivan