newbie question about DTML IF
I'm trying to add a statement to my page that greets each user with a different statement, but i can't seem to work out how to do it. Just from reading some of the zope documentation i've tried: <dtml-if expr="AUTHENTICATED_USER = bob"> bob likes to eat fish </dtml-if> and <dtml-if expr="str(GetUser()) = bob"> bob likes to eat fish </dtml-if> Both of these are obviously very wrong, in the first case i thought it might have something to do with calling an object and trying to compare it to a string so in the second one i tried rendering it into a string, but evedently this isn't the correct way to do that. I'm new to both zope and python and I have a feeling I have the whole thing totally wrong. Would it be better to do this in python some how and store each users greeting in a dtml document? any suggestions would be greatly appreciated Thanks Myles
Myles Byrne wrote:
I'm trying to add a statement to my page that greets each user with a different statement, but i can't seem to work out how to do it.
Just from reading some of the zope documentation i've tried:
<dtml-if expr="AUTHENTICATED_USER = bob"> bob likes to eat fish </dtml-if>
and
<dtml-if expr="str(GetUser()) = bob"> bob likes to eat fish </dtml-if>
Both of these are obviously very wrong, in the first case i thought it might have something to do with calling an object and trying to compare it to a string so in the second one i tried rendering it into a string, but evedently this isn't the correct way to do that. I'm new to both zope and python and I have a feeling I have the whole thing totally wrong.
Would it be better to do this in python some how and store each users greeting in a dtml document?
any suggestions would be greatly appreciated
Thanks
Hi, Myles Equality-testing in python uses "==", not " =". Easy mistake. -- Jim Washington
I am not sure about he expression, but normally you should use '==' for an equals comparison <dtml-if "A==B">..... Tom => -----Original Message----- => From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Myles => Byrne => Sent: Wednesday, 24 October 2001 9:17 PM => To: zope@zope.org => Subject: [Zope] newbie question about DTML IF => => => I'm trying to add a statement to my page that greets each user with a => different statement, but i can't seem to work out how to do it. => => Just from reading some of the zope documentation i've tried: => => <dtml-if expr="AUTHENTICATED_USER = bob"> => bob likes to eat fish => </dtml-if> => => and => => <dtml-if expr="str(GetUser()) = bob"> => bob likes to eat fish => </dtml-if> => => Both of these are obviously very wrong, in the first case i thought it => might have something to do with calling an object and trying to compare => it to a string so in the second one i tried rendering it into a string, => but evedently this isn't the correct way to do that. I'm new to both => zope and python and I have a feeling I have the whole thing totally => wrong. => => Would it be better to do this in python some how and store each users => greeting in a dtml document? => => any suggestions would be greatly appreciated => => Thanks => => Myles => => => _______________________________________________ => 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 ) =>
* Myles Byrne <wisemanb@ihug.com.au> [011024 12:20]:
I'm trying to add a statement to my page that greets each user with a different statement, but i can't seem to work out how to do it.
<dtml-if expr="AUTHENTICATED_USER = bob"> bob likes to eat fish </dtml-if>
Two points to note: 1) Wrong operator. = is an assignment operator (a=3 means 'assign the value 3 to the variable a). you want ==, which tests equality. 2) you're comparing a string, 'bob' to a non-existent variable, bob. when you're inside quotes, you're in python. "bob" therefore refers to a variable by the name of bob. AUTHENTICATED_USER is a string (in this case, 'bob'), not a variable. You want
<dtml-if expr="AUTHENTICATED_USER == 'bob'"> bob likes to eat fish </dtml-if>
hth seb
participants (4)
-
Jim Washington -
Myles Byrne -
seb bacon -
Tom Cameron