Hi,

I must preface by saying that I'm relatively new to ZPT, and haven't been
using it in the context of Zope. Having said that, however, I think that
what follows is still applicable.

Two things that have struck me as potentially useful additions have been
a syntax for expressing case statements and arguments to macros (slots
are useful, but aren't applicable when, for instance, you want to write
a macro to mark up an arbitrary object). Both of these are essentially
syntactic sugar, but (imho) improve readability and aid brevity.

The syntax I have come up with (and have an implementation for) is as
follows:

case statements:

two new attributes are added: tal:switch and tal:case.

as an example:

<table tal:repeat="row rows"
       tal:switch="row/rowtype">
  <tr tal:case="string:group">...</tr>
  <tr tal:case="string:user">...</tr>  
  <tr tal:case="string:files">...</tr> 
</table>                        

compare:

<table tal:repeat="row rows">
  <tal:block tal:define="casevar row/rowtype">
    <tr tal:condition="python:casevar='group'">...</tr>
    <tr tal:condition="python:casevar='user'">...</tr>
    <tr tal:condition="python:casevar='files'">...</tr>
  </tal:block>
</table>

This is essentially the same as using tal:define and multiple tal:condition
blocks, except for the fact that the case values aren't part of the visible
variable space. Missing at the moment are:

* ways to change the type of comparison used in the case test.
* a sensible definition of how a default case should work.
  (this is actually pretty obvious, but would require more work, as the
   case statements can't be simply treated like conditionals)

macro arguments:

metal:use-macro tags allow metal:arguments="define_list" which defines a
set of variables in a new local scope in which the macro is executed.

if tal:define could be used in conjunction with metal:use-macro in such
a way as to have the define executed first, then the additional tag
wouldn't be required. My reading of the docs suggests that there's reason
for the ordering of excution of tal: and metal: tags, so the new tag
may well be the only way.

<tal:block metal:use-macro="a_macro"
           metal:arguments="obj path/to/an/object;
                            verbose python:1" \>

compare:

<tal:block tal:define="obj path/to/an/object;
                       verbose python:1">
  <tal:block metal:use-macro="a_macro" \>
</tal:block>

Toby.

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to