[ZPT] Re: DTML/ZPT examples

Peter Bengtsson mail@peterbe.com
Wed, 13 Jun 2001 10:34:38 +0200


I added it http://www.zope.org/Members/peterbe/DTML2ZPT/#example2
but I put it aside a little bit because it is more "advanced" than the
existing one. I like the first example because it is so easy see understand
and demonstrates the basics of TAL.
Peter

> Hi Peter,
>
> I was looking over your DTML to ZPT example page (great job by the
> way!).  I think there is a better way to approach example 2:condition
> testing.
>
> Currently you have:
>
> <H4>
> <span tal:replace="template/title"
>         tal:condition="python:len(result)==0"/>
> <span tal:replace="string:Untitled"
>         tal:condition="python:not(len(result)==0)"/>
> </H4>
>
> which works, but requires the use of an extra span tag.  I would like
> to propose the following alternative:
>
> <H4 tal:content="python:test(len(result)==0, path('template/title'),
'Untitled')">Dummy Title</H4>
>
> which achieves the same effect.
>
> Keep up the good work!
>
> --Brent
>
> On Mon, May 28, 2001 at 10:06:10AM +0200, Peter Bengtsson wrote:
> > Content changed. (2001-05-28 03:57)
> >
> > Cool!
> > That's great. I was hoping that the community could help me with that
page.
> > If you want to add anything new, I'll add it without doubt, now that you
> > have proved skilled enough :)
> >
> > perhaps you can translate this one for me?
> >
> > DTML:
> > <dtml-with subfolder>
> >   <dtml-if anotherpageobject>
> >     <tr>
> >         <td><dtml-var "anotherpageobject.title"></td>
> >         <td><a href="<dtml-var "anotherpageobject.absolute_url()">"
> > title="<dtml-var "anotherpageobject.title">"><dtml-var
> > "anotherpageobject.title"></td>
> >     </tr>
> >   </dtml-if>
> > </dtml-with>
> >
> > 'anotherpagepobject' might not even exist. I.e. not created yet.
> > The ZPT must skip the whole <TR> tag if the object doesn't exist.
> >
> > Can we have some support from the rest of the ZPT mailing list on how to
use
> > the latest spec and the flashy path things et al that DC have recently
> > released?
> >
> > Cheers, Peter
> >
> > PS. Andreas, CC in the zpt so when can all enjoy your replies.
> >
> > ----- Original Message -----
> > From: "Andreas Vallen" <vallen@gmx.net>
> > To: "Peter Bengtsson" <mail@peterbe.com>
> > Sent: Friday, May 25, 2001 6:42 PM
> > Subject: Re: DTML/ZPT examples
> >
> >
> > > Hi Peter,
> > >
> > > I`ve just taken the time to check out your changed ZPT/DTML
> > > example code #2.
> > > Amazing how something seemingly this simple makes me become confused.
> > > I think we still haven't got it right though.
> > >
> > > you wrote:
> > > "Both BL will print the <H4> tags independent of what happens."
> > >
> > > Unfortunately this seems not to happen:
> > > "tal:condition" makes the whole tag disappear if it is not met.
> > > Even in conjunction with "tal:content"
> > >
> > > So:
> > > <H4 tal:content="template/title"
> > >     tal:condition="python:0">
> > >   Untitled</H4>
> > >
> > > will render as nothing (""). Not even the H4-Tag will show up.
> > >
> > > I make the following proposal:
> > >
> > > DTML:
> > > <dtml-if "_.len(result)==0">
> > >   <H4><dtml-var document_title></H4>
> > > </dtml-if>
> > >
> > > <H4 tal:content="template/title"
> > >     tal:condition="python:len(result)==0">
> > > </H4>
> > >
> > >
> > > If no title exists nothing will get rendered.
> > > To render "untitled" in this case one could use your
> > > current DTML-example:
> > >
> > > <H4>
> > > <dtml-if "_.len(result)==0">
> > >   <dtml-var document_title>
> > > <dtml-else>
> > >   Untitled
> > > </dtml-if>
> > > </H4>
> > >
> > > and the following ZPT:
> > >
> > > <H4>
> > >   <span tal:replace="template/title"
> > >         tal:condition="python:len(result)==0"/>
> > >   <span tal:replace="string:Untitled"
> > >         tal:condition="python:not(len(result)==0)"/>
> > > </H4>
> > >
> > > I think this is necessary - we don't have "else" in
> > > ZPT, so we use "tal:condition" with the inverse expression.
> > >
> > > Your page is a good help for anyone starting to grasp ZPT.
> > > Good work. Especially regarding the shortage of documentation
> > > of our supposed new Templating mechanism of choice.
> > >
> > > Ciao, Andreas
> > >
> > >
> > >
> > > Montag, 21. Mai 2001 10:50 you wrote:
> > > > Cheers!
> > > >
> > > > <H4>
> > > > <dtml-if "_.len(result)==0">
> > > >   <dtml-var document_title>
> > > > <dtml-else>
> > > >   Untitled
> > > > </dtml-if>
> > > > </H4>
> > > >
> > > > |-split-|
> > > >
> > > > <H4 tal:content="template/title"
> > > >     tal:condition="python:len(result)==0">
> > > >   Untitled</H4>
> > > >
> > > >
> > > >
> > > > Better?
> > > >
> >
http://www.zope.org/Members/peterbe/DTML2ZPT_Conversion_examples/#example2
> > > >
> > > > Is this right?
> > > > Both BL will print the <H4> tags independent of what happens.
> > > > If the python:len(result) condition is met, the tal:replace occurs.
If
> > the
> > > > condition thing "fails", it leaves the ZPT alone on that tag.
> > > >
> > > > Swedish?
> > > >
> > > > Peter
> > > > ----- Original Message -----
> > > > From: "Andreas Vallen" <vallen@gmx.net>
> > > > To: <mail@peterbe.com>
> > > > Sent: Friday, May 18, 2001 4:51 AM
> > > > Subject: DTML/ZPT examples
> > > >
> > > > > Hi,
> > > > >
> > > > > I just looked at your DTML vs. ZPT page.
> > > > > I think I've found an error in your second example.
> > > > > If the condition in the ZPT example evaluates to
> > > > > true then the whole tag gets replaced - including
> > > > > the "<h4>" which does not happen in the DTML example.
> > > > > We get the same output by replacing
> > > > > "tal:replace" with "tal:content."
> > > > >
> > > > > DTML:
> > > > > <dtml-if "_.len(result)==0">
> > > > >   <H4>Monkey!!</H4>
> > > > > </dtml-if>
> > > > >
> > > > > ZPT:
> > > > > <H4 tal:replace="template/title"
> > > > >     tal:condition="python:len(result)==0">
> > > > >   Might display Monkey</H4>
> > > > >
> > > > > Bye,
> > > > > Andreas
> >
> >
> > _______________________________________________
> > ZPT mailing list
> > ZPT@zope.org
> > http://lists.zope.org/mailman/listinfo/zpt
>
> -------------------------------------------------------------------------
>
> "The programmer, like the poet, works only slightly removed from pure
>  thought-stuff.  He builds his castles in the air, from air, creating
>  by exertion of the imagination.  Few media of creation are so
>  flexible, so easy to polish and rework, so readily capable of
>  realizing grand conceptual structures."
>                         -- Frederick Brooks, Jr., The Mythical Man Month
>
> _______________________________________________
> ZPT mailing list
> ZPT@zope.org
> http://lists.zope.org/mailman/listinfo/zpt