[Zope] nested logic in DTML

Nick Garcia ngarcia@codeit.com
Wed, 28 Jul 1999 15:26:53 -0700


At 06:11 PM 7/28/99 -0400, Jeffrey Shell wrote:
>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.

Hmmm... interesting.  I haven't really worked with Zope2 very much, but in
1.10.x, my solution to this problem was always to do it this way:

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

This way, Zope gets the headers first and doesn't complain, the logic still
runs the same, and everything comes out hunky-dory.  Of course this
wouldn't help if DoSomething actually needed to set an environment variable
that goes in the header.... And index_html can't have any header or footer
information, but I've usually been able to work around that.
Nick Garcia | ngarcia@codeit.com
CodeIt Computing | http://codeit.com