September 27th, 2002, 07:52 AM
evaluating a dtml expression
I have a problem with this code:
<h3>Hello <dtml-var user_name> !</h3><br>
Pretty simple huh? It is meant to use "test", a zsql method, to check whether a certain username exists. The username is stored in a Postgresql database table.
(The user_name is entered on a previous form so this code is on the feedback form.)
My problem is that the "if" returns true even when there is no matching name found with the one I input. What gives?
PS. This worked fine when I was evaluating variables.
October 3rd, 2002, 04:51 PM
Remember that expr="" attributes on DTML tags are evaluated as Python expressions.
Basically what your code is doing is seeing if there is "test" in the namespace, which there is, since you have the ZSQL method, but it's not actually calling the ZSQL Method.
Here's what you need to do:
By using "test()", with the parentheses, you are calling the method "test." And you have to pass the keyword argument because ZSQL methods only aquire the REQUEST object if they are called from the web. We are calling this one in a DTML Document or Method, so it won't aquire REQUEST.
<dtml-if expr="test(user_name - user_name)">
<h3>Hello, <dtml-var user_name>!</h3><br>
Note that you could also pass it the entire REQUEST if you like... like this:
One more thing...
Be sure user_name is in your ZSQL Method's arguments, if you pass the variable by keyword.