[Zope] nested logic in DTML

Jeffrey Shell Jeffrey@digicool.com
Wed, 28 Jul 1999 18:11:20 -0400


> I'd like to add another fairly long conditional right before the
> update line, but it makes things quite unwieldy. What I'd really like
> would be a DTML Document like object that can return a value. I could
> stick the long conditional in that object. Then I could reference the
> object in several different places and just check the return value.
> 
> I realize that this is stretching DTML beyond it's presentation-only
> design, but I do think that going all of the way to an 
> external python 
> method for this seems a bit much.

(a) Use DTML Methods if you're planning on returning a value, that way
the concept of methods stays solid,

and (b) In the Zope 2 Beta there is the new "return" tag.  It was
submitted by someone on this list.  I've started using it a little bit
myself, but I haven't used it to return non-dtml-documents.  This is
probably what you're looking for.

I've found the return tag very nice for when I had situations (similar
to what you described) of having heaps of logic before any content,
usually on something that happens after submitting a form.  If you had a
DTML Document/Method like the following:

<!--#if something-->
 <!--#in something_else-->
  <!--#call "DoSomething(with=_['sequence-item']"-->
 <!--#else-->
  <!--#call "DoNothing(with="_['sequence-item']"-->
 <!--#/in-->
 <!--#var index_html-->
<!--#else-->
<!--#var standard_html_header-->
 <h1 align="center" style="color:red;">Boo!</h1>
<!--#var standard_html_footer-->

It may very likely (when rendered) leave one or more blank lines at the
top, which Zope will try (unsuccesfully) to parse for HTTP Headers.
Now, instead of #var index_html, I can have #return index_html and (thus
far) it seems to do the right thing.