#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    kenya
    Posts
    0
    Rep Power
    0

    evaluating a dtml expression


    I have a problem with this code:

    <dtml-if expr="test">
    <h3>Hello <dtml-var user_name> !</h3><br>
    </dtml-if>

    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?

    Mutinda.
    PS. This worked fine when I was evaluating variables.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    St. George, Utah
    Posts
    63
    Rep Power
    37
    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:
    Code:
    <dtml-if expr="test(user_name - user_name)">
      <h3>Hello, <dtml-var user_name>!</h3><br>
    </dtml-if>
    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.

    Note that you could also pass it the entire REQUEST if you like... like this:
    Code:
    <dtml-if expr="test(REQUEST=_.REQUEST)">
    One more thing...
    Be sure user_name is in your ZSQL Method's arguments, if you pass the variable by keyword.
    Lucas Marshall

IMN logo majestic logo threadwatch logo seochat tools logo