[Zope] Getting an object from it's id

Geoff Armstrong geofstro@monaco.mc
Tue, 23 Jan 2001 14:11:12 +0000


on 1/23/01 1:20 PM, Ivan Cornell at ivan.cornell@framestore.co.uk wrote:


Hi Ivan,

Thanks. The "_.getitem(myId)" works well. I've made a note of the "hasattr"
trick as well for future reference.


Geoff
> 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
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )