[Zope] passing arguments from dtml methods to SQL methods

Peter Sabaini sabaini@niil.at
Wed, 29 Mar 2000 13:46:33 +0200 (CEST)


if you want to pass variables to a dtml method you have the option to
set it in the REQUEST object eg.

  <dtml-call "REQUEST.set('varname', 'somestringval')">

or put it in the namespace eg.

  <dtml-let varname="'somestringval'">

then call your method as per normal eg. <dtml-var yourmethod> which
then will find the vars you set before.

or you call your method with keyword args like

  <dtml-var "yourmethod(_.None, _, varname='somestringval')">


note the difference between 

  <dtml-var "method"> which is <dtml-var expr="method">

and 

  <dtml-var method> which is <dtml-var name="method">


see the "Document Template Markup Language Reference",
http://www.zope.org/Documentation/Guides/DTML and the zope howto's. 

peter.

On Wed, 29 Mar 2000, Allen Wallis wrote:

:Hi,
:Thanks for previous help on the namespace variable '_', much
:appreciated!
:
:I have another problem though, how does one pass parameters between DTML
:methods, and from dtml methods to ZSQL methods?
:
:I have a DTML method "getSearchResults" that gets called when a form is
:posted using
:<FORM... action="getSearchResults">
:<INPUT NAME="fname"
:</FORM>
:The method gets called and magically the form fields like fname
:described in the above form are accessible from the dtml method, so I
:can do <dtml-var fname> and there's the input from the user. (I still
:don't fully understand how that bit of black magic works...)
:
:Ok, then I have a ZSQL method with fname as an argument, and again, when
:my dtml method calls the zsql method, that variable fname can be
:accessed using <dtml-var fname> in the SQL query. While maybe I don't
:completely understand what's happening, I can still use it. The problem
:now is, my ZSQL method needs to have an argument "tablename" that it can
:use so that a different table can be selected, however, this tablename
:is not under the user's direct control. It gets set according to some
:choices that the user makes along the way. I would hence need to
:"declare" it in the dtml method "getSearchResults", initialise it, and
:pass it to the ZSQL method so that the ZSQL method can use it. I tried
:doing the following: (suppose the ZMYSQL method's id is "searchMySQL").
:in the dtml method:
:    <dtml-if expr="whatever">
:       <dtml-var name="getSearchResults(fname=fname,
:tablename='suppname')">
:    </dtml-if>
:So that didn't work, but maybe it describes what I'm trying to do - that
:is, fname exists and is initialised from the user's form input, but
:I want to create the variable tablename, and pass it to another method
:(or just create in the namespace space so that it's accessible to other
:methods).
:
:Sorry to be so long-winded, trying my best to describe things with my
:very limited knowledge of zope/python.
:
:Many thanks
:Allen

-- 

_________________________________________________
peter sabaini, mailto: sabaini@niil.at
-------------------------------------------------