[Zope] dtml-in statement with mysql

Chris Kratz chris.kratz at vistashare.com
Fri Sep 19 13:28:31 EDT 2003


Hello Steve,

One thing you can do, is place all the code that you want to run inside the 
dtml-in statements into a separate dtml-method.  Then you can do the 
following...

<dtml-if expr="search_method == '1'">
 <dtml-in sql_1>
  <dtml-var searchList>
 </dtml-in>
<dtml-elif expr="search_method == '2'">
 <dtml-in sql_2>
    <dtml-var searchList>
 </dtml-in>
</dtml-if>

where searchList is the dtml that displays the results.

Another option as Scott suggested is to use a python script which is actually 
much cleaner.  Something like the following should work...

## Script (Python) "searchScript"
##bind container=container
##bind context=context
##bind namespace=_
##bind script=script
##bind subpath=traverse_subpath
##parameters=search_method
##title=
##
if search_method=='1':
   return context.sql_1()
elif search_method=='2':
   return context.sql_2()
else:
   pass # do nothing, perhaps raise an error?

Then your dtml page becomes...

<dtml-in "searchScript(search_method=search_method)">
   ... result html/dtml
</dtml-in>

One issue with the second one is that if you have any parms for your sql, you 
will have to explicitly pass them through the python into the sql methods.

-Chris

On Friday 19 September 2003 1:00 pm, Steve Lenti wrote:
> I have a small question.  I have a couple of sql methods defined and
> depending on the search method I want to excute a specific one and
> return the results.  I want to do something like this
>
> <dtml-if expr="search_method == '1'">
>  <dtml-in sql_1>
> <dtml-elif expr="search_method == '2'">
>  <dtml-in sql_2>
> </dtml-if>
> ... the rest of the the results
>
> the problem I have is that zope doesn't like me using dtml-in statements
> inside the if statements unless I copy the whole results page into the
> if statement.  What I want to do is depending on what the search_method
> variable is I want to call a specific sql method without having to put
> all the code in each if statement.  is there anyway to accomplish this.
> hope I have been clear enough.
>
> thanks in advance,
>
> --STEVE
>
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )

-- 
Chris Kratz
Systems Analyst/Programmer
VistaShare LLC
www.vistashare.com




More information about the Zope mailing list