[Zope] Newbie - DTML if to ZPT if
Tino Wildenhain
tino at wildenhain.de
Fri Dec 5 03:48:40 EST 2003
hi anonymous fowlersomething,
fowlertrainer at anonym.hu schrieb:
> Hello !
>
> Sorry for lamer question.
> I has been used DTML, and some things are don't know in ZPT.
>
> How to I replace this DTML pseudo-code with ZPT:
>
> 1.)
>
> === DTML ===
> <dtml-if logined=1>
> <table>SomeTable1</table>
> <dtml-else>
> <table>SomeTable2</table>
> </dtml-if>
either use 2 PageTemplates and a "wedge" script to
call one or the other (depends on the content)
or use <table tal:condition ...>
or use the same table if the structure is compareable
and use different data source.
> ==ZPT==
> ??????
>
> 2.)
> How to define multiple (array) variable in zpt ?
> Like this:
>
> MyArray=[['A',1],['B',2],['C',3]]
You better dont do it. ZPT is meant to be
a display layer and _not_ a layer for logic.
However you could to that, but you are highly
discouraged to do so unless you have reay strong
requirements (and I doubt that is the case)
You are better of defining your logic outside
in one or a couple of python script object
you call or turn it around and call the ZPT
from python script.
>
> 3.)
> How to I raise and catch exception with ZPT ?
you can somewhat catch but not really raise.
ITs for the same reason I mentioned above.
>
>
>
>
> In this time I use Scripts like this to replace dtml elements, but
> this way is same as normal web-scripting (mod_php/py), not zope-kind.
> ==script1==
> l=[]
> if logined:
> l.append('<table>SomeTable1</table>')
> ...
> else:
> l.append('<table>SomeTable2</table>')
> ...
> return("\n".join(l))
>
> ... tal:replace structure python:here.script1>
>
You dont do this. Let HTML be in the Template
where it belongs.
You see the template as a draft of the finally
displayed page. TAL is used to change part
of the DOM to reflect your data and such.
TAL has tal:condition, tal:contents, tal:attributes
and others for this task.
There is METAL to help you assembling your Templates
from bigger pieces and have reuseable HTML parts.
Read the references on TAL carefully and dont
try to follow too close the examples of the
DTML to ZPT liga.
Regards
Tino Wildenhain
More information about the Zope
mailing list