[Zope] A conditional dtml-in tag?

Small Business Services toolkit at magma.ca
Mon Feb 16 12:03:49 EST 2004


I have used this type of approach before:

<dtml-if pns>
  <dtml-call "REQUEST.set('searchfield', 'nameserver1')">
  <dtml-call "REQUEST.set('searchcriteria', pns)">
</dtml-if>

<dtml-if org>
  <dtml-call "REQUEST.set('searchfield', 'org')">
  <dtml-call "REQUEST.set('searchcriteria', org)">
</dtml-if>

<dtml-in "Catalog({searchfield : searchcriteria})">


You may be able to adapt this approach...


HTH

Jonathan



----- Original Message -----
From: "RI Dunfey" <s0231134 at sms.ed.ac.uk>
To: <zope at zope.org>
Sent: February 16, 2004 11:32 AM
Subject: [Zope] A conditional dtml-in tag?


>
> Hi-
>
> I have a dtml page which displays the results of a sql query:
>
> <dtml-in expr="my_query(category1=category1, category2=category2)">
> <TR><TD>
> <dtml-var NAME>
> </TR></TD>
> </dtml-in>
>
> The values that are passed to the query are obtained from the request
object.
> If the value for category2=None then I want to leave category2 out of the
sql
> query as below:
>
> <dtml-in expr="my_query(category1=category1)">
> <TR><TD>
> <dtml-var NAME>
> </TR></TD>
> </dtml-in>
>
> The sql query has been designed to handle this using the optional tag.
>
> However, it falls over if I break the in tags up with an if tag, e.g.:
>
> <dtml-if "category2=None">
> <dtml-in expr="my_query(category1=category1)">
> <dtml-else>
> <dtml-in expr="my_query(category1=category1, category2=category2)">
> </dtml-if>
> <TR><TD>
> <dtml-var NAME>
> </TR></TD>
> </dtml-in>
>
>
> I have also tried passing a string to the in tag, e.g.:
>
> <dtml-if "category2=None">
> <dtml-var dummystr="my_query(category1=category1)">
> <dtml-else>
> <dtml-var dummystr="my_query(category1=category1, category2=category2)">
> </dtml-if>
> <dtml-in expr=<dtml-var dummystr>>
> <TR><TD>
> <dtml-var NAME>
> </TR></TD>
> </dtml-in>
>
> but the in tag cannot except a string?  I have also tried handling this in
> python, as it is logic, however this too has been unsuccessful and would
quite
> allow me to format the results as desired.  I just want to control how the
sql
> query is executed?  Depending on the value of variables in the request
object.
>
> Any help, much appreciated,
>
> Rob
>
> _______________________________________________
> 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 )




More information about the Zope mailing list