[ZPT] Re: DTML/ZPT examples

Peter Bengtsson mail@peterbe.com
Mon, 28 May 2001 10:06:10 +0200


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