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
your dtml-nesting is not allowed and not supported. call the corresponding zsql based on your condition *outside* dtml-in, assign the result to a variable and *then* use dtml-in to iterate over the result list. -aj --On Freitag, 19. September 2003 11:00 Uhr -0600 Steve Lenti <slenti@abqpubco.com> 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@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 )
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@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
On Fri, Sep 19, 2003 at 01:28:31PM -0400, Chris Kratz wrote:
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.
thanks very much for your suggestions. The first 1 worked perfectly and was exactly what I was looking for. --STEVE You don't become a failure until you're satisfied with being one.
participants (3)
-
Andreas Jung -
Chris Kratz -
Steve Lenti