[Zope] zope and python script
Thomas B. Passin
tpassin@mitretek.org
Wed, 27 Feb 2002 14:22:55 -0500
[Frank Tegtmeyer]
> <mbagepll@memphis.edu> writes:
>
> > <dtml-in expr="Python_script()">
> > <li>
> > <dtml-var text>
> > </li>
> > </dtml-in>
>
> with <dtml-var sequence-item> you get the elements of your list. If
> these elements have attributes that you want to access then DTML
> provides them directly with their name. Suppose you have list elements
> with the attributes name and price you would use:
>
> <dtml-in expr="Python_script()">
> <dtml-if sequence-start>
> <ul>
> </dtml-if>
> <li><dtml-var name>: <dtml-var price></li>
> <dtml-if sequence-end>
> </ul>
> </dtml-if>
> <dtml-else>
> <p>Sorry, nothing found.</p>
> </dtml-in>
>
Frank, I'm going take exception to your way of using "if" statements
separately around start and end tags (I mean the <ul> tags). It's true that
it works here, but it's better not to produce unbalanced parts in a markup
element in separate and uncoordinated places. If you were to try to port
this to something written in xml, where the tags have to nest properly, for
example, it wouldn't work.
I'm suggesting that it is a good idea to try produce things that have to be
balanced in a balanced way, even though it may not be strictly necessary.
It will be better in the long run, and less prone to error if something
doesn't work as expected inside statement blocks. <ul> tags have to be
balanced.
In this case, it oculd be done like this:
<ul>
<dtml-in expr="Python_script()">
....
</dtml-in>
</ul>
If you don't want to have the possiblity of an empty <ul> element, you could
write
<dtml-let List=Python_script>
<dtml-if List>
<ul>
<dtml-in List>
...
</dtml-in>
</ul>
</dtml-if>
</dtml-let>
Cheers,
Tom P