[Zope] A conditional dtml-in tag?

Terry Hancock hancock at anansispaceworks.com
Tue Feb 17 10:29:33 EST 2004


On Monday 16 February 2004 10:32 am, RI Dunfey wrote:
> 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:

One solution is to call the query from Python and have a Python script like:

if REQUEST.category2:
	return context.my_query(category1=category1, category2=category2)
else:
	return context.my_query(category1=category1)

Which is clearer to read. However, you can use the "and-or" idiom directly in DTML,
if you want to avoid the extra script (this is roughly equivalent to converting the
if-else above into an expression):

<dtml-in expr="category2 and
			my_query(category1=category1, category2=category2)
			or
			my_query(category1=category1)">
     <dtml-var NAME>  <!-- put your loop contents here -->
</dtml-in>

HTH,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com



More information about the Zope mailing list