Here's a nubie question. If I am using two string values in a <dtml-if> tag why is it not evaluating to true? s1 = 'Hello' s2 = 'Hello' <dtml-if "s1==s2"> <-- This is returning 0 Stuart Foster MediServe Information Systems
On Mon, May 15, 2000 at 11:46:25AM -0700, Stuart Foster wrote:
Here's a nubie question. If I am using two string values in a <dtml-if> tag why is it not evaluating to true?
s1 = 'Hello' s2 = 'Hello'
<dtml-if "s1==s2"> <-- This is returning 0
Are you sure you are comparing two strings? The only explanation I see is that the above is just a simplified testcase of what you think is happening. When you compare, for example 'id' with 'foo', where <dtml-var foo> renders 'foo', "id=='foo'" will still yield false. This is because 'id' is, on many objects, a method, while on others it is a property. In this example you'd be comparing the method object with a string, which always yields false, while the comparison "id()=='foo'" would yield true! Now, in order to allow for both cases, one where id is a string property (and can be compared using "id=='foo'", and the case where id is a method, use the following syntax: "_['id'] == 'foo'" This is, under the hood, the same as <dtml-var id>, which will call id if it is a method, and otherwise will just return the value of the 'id' property or variable. -- Martijn Pieters | Software Engineer mailto:mj@digicool.com | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ | The Open Source Web Application Server ---------------------------------------------
Hi Martijn,
-----Original Message----- From: Martijn Pieters [mailto:mj@zopatista.com]On Behalf Of Martijn Pieters Sent: maandag 15 mei 2000 21:25 To: Stuart Foster Cc: 'zope@zope.org' Subject: Re: [Zope] <dtml-if> String question
[snip]
When you compare, for example 'id' with 'foo', where <dtml-var foo> renders 'foo', "id=='foo'" will still yield false. This is because 'id' is, on many objects, a method, while on others it is a property. In this example you'd be comparing the method object with a string, which always yields false, while the comparison "id()=='foo'" would yield true!
Up to now I have been using "id == 'foo'" without problems. So what I would like to know now is in which case(s) id is a method and in what case(s) id is a property. Enlighten me, please. cb
Is it possible that the variables may have extraneous leading and/or trailing spaces? If so try using: <dtml-if "_.string.strip(s1)==_.string.strip(s2)"> __________________________________________________________________ Jim Sanford . Database Engineer / \ / Accelerated Technology, Inc. / / 720 Oak Circle Drive East / / \ Mobile, AL 36609 / / \ Voice: 334-661-5770 fax: 334-661-5788 / \ E-Mail: jsanford@atinucleus.com Web: http://www.atinucleus.com Nucleus. All You NEED in an RTOS. Royalty Free __________________________________________________________________ ----- Original Message ----- From: Stuart Foster <stuartf@mediserve.com> To: <zope@zope.org> Sent: Monday, May 15, 2000 1:46 PM Subject: [Zope] <dtml-if> String question Here's a nubie question. If I am using two string values in a <dtml-if> tag why is it not evaluating to true? s1 = 'Hello' s2 = 'Hello' <dtml-if "s1==s2"> <-- This is returning 0 Stuart Foster MediServe Information Systems
_______________________________________________ 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 )
On Mon, 15 May 2000, Stuart Foster wrote:
Here's a nubie question. If I am using two string values in a <dtml-if> tag why is it not evaluating to true?
s1 = 'Hello' s2 = 'Hello'
<dtml-if "s1==s2"> <-- This is returning 0
How do do the values get set? Are you sure they are identical? How are you checking the -if return result? Your -if syntax looks correct to me. --RDM
Stuart Foster wrote:
Here's a nubie question. If I am using two string values in a <dtml-if> tag why is it not evaluating to true?
s1 = 'Hello' s2 = 'Hello'
<dtml-if "s1==s2"> <-- This is returning 0
When I view the following DTML method, I get a "1". <dtml-let s1="'hello'" s2="'hello'"> <dtml-var "s1==s2"> </dtml-let> Can you provide a full example where you're getting unexpected behaviour? -- Steve Alexander Software Engineer Cat-Box limited
participants (6)
-
Cornelis J. de Brabander -
Jim Sanford -
Martijn Pieters -
R. David Murray -
Steve Alexander -
Stuart Foster