I apologize for the (probably FAQ) newbie problem. FedEx hasn't delivered my copy of "The Zope Book" or "Programming Python" yet, so please forgive me. Suppose I have the name of an object in variable `foo'. I would like to test for the existence of the named object. Suppose that foo=='bar'. The following won't work: <dtml-if foo> <br>Yep! </dtml-if> because `foo' will always have a value. How, then, can I see if `bar' exists? A million thanks, -- Kirk Strauser
This is a newbie hack at the Q: Maybe you can instantiate foo to a null variable in the REQUEST namespace <dtml-call expr="REQUEST.set(foo,'')"> and then...later in your objects <dtml-unless expr="foo == ''"> <br>yep </dtml-unless> -Trevor
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Kirk Strauser Sent: Tuesday, October 16, 2001 10:04 AM To: zope@zope.org Subject: [Zope] Newbie dereferencing problem
I apologize for the (probably FAQ) newbie problem. FedEx hasn't delivered my copy of "The Zope Book" or "Programming Python" yet, so please forgive me.
Suppose I have the name of an object in variable `foo'. I would like to test for the existence of the named object. Suppose that foo=='bar'. The following won't work:
<dtml-if foo> <br>Yep! </dtml-if>
because `foo' will always have a value. How, then, can I see if `bar' exists?
A million thanks, -- Kirk Strauser
_______________________________________________ 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 )
At 2001-10-16T15:10:22Z, "Trevor Toenjes" <zope@toenjes.com> writes:
This is a newbie hack at the Q: Maybe you can instantiate foo to a null variable in the REQUEST namespace <dtml-call expr="REQUEST.set(foo,'')"> and then...later in your objects
<dtml-unless expr="foo == ''"> <br>yep </dtml-unless>
I think that maybe I should have elaborated on my problem. I have a database with a column named 'imagename'. Inside a <dtml-in> query, then, imagename will be the name of a Zope object that may or may not exist. If the named object exists, then I want to perform one set of actions on the object. Otherwise, I want to perform another set of actions to create the object. Given the following database 'imagetable': ID imagename -- ---------- 1 images/foo 2 images/bar 3 otherstuff/baz and an SQL query method: getStuff: select * from imagetable Then in this loop: <dtml-in getStuff> <dtml-var imagename> </dtml-in> imagename will always exist, and it will always have a value (namely 'images/foo', 'images/bar', then 'otherstuff/baz'). I'm not interested in checking whether imagename has a value - I want to see if the string stored in imagename is a Zope object that exists. -- Kirk Strauser
On Tuesday 16 October 2001 10:04 am, Kirk Strauser allegedly wrote:
I apologize for the (probably FAQ) newbie problem. FedEx hasn't delivered my copy of "The Zope Book" or "Programming Python" yet, so please forgive me.
Suppose I have the name of an object in variable `foo'. I would like to test for the existence of the named object. Suppose that foo=='bar'. The following won't work:
<dtml-if foo> <br>Yep! </dtml-if>
because `foo' will always have a value. How, then, can I see if `bar' exists?
A million thanks,
try: <dtml-if expr="_.has_key(foo)"> there is an object named <dtml-var name="foo">! </dtml-if> hth, /---------------------------------------------------\ Casey Duncan, Sr. Web Developer National Legal Aid and Defender Association c.duncan@nlada.org \---------------------------------------------------/
participants (3)
-
Casey Duncan -
Kirk Strauser -
Trevor Toenjes