[Zope-Moz] Templates anyone?

Shalabh Chaturvedi shalabh@pspl.co.in
Sun, 27 Feb 2000 20:20:10 +0530


From: Martijn Pieters <mj@digicool.com>
> From: Shalabh Chaturvedi [mailto:shalabh@pspl.co.in]
> > Martijn Pieters wrote:
> > >
> > > That's exactly what the component tag is so handy for:
> > >
> > >   <dtml-let resultset="'name_of_sql_method'" show_next_prev="1"
> > >             head="'<th>id</th><th>value</th>'">
> > >     <dtml-component component="batched_resultstable">
> > >       <td>&dtml-id;</td><td>&dtml-value;</td>
> > >     </dtml-component>
> > >   </dtml-let>
> > >
> > > Above code would be generated by ZopeStudio.
> >
> > I'd also like to see how 'batched_resultstable' is defined.
> > Is this thing
> > implemented already? (why don't I know?)
>
> It is something I just made up, but that would work, if/when the
> dtml-component tag is included in Zope.
>
> It just is a callable object, that gets fed a attribute named
> component-contents with the dtml code in within the block in it.

I feel this might not be enough. There should not be just _one_
component_contents but it should be possible to pass any number of parameters
to the template. Like so:

<dtml-component   template="table_filled_with_results"
                              query="mySQLMeth"
                              columns2use="Name, Age"
                              tableAttributes=" width=100% "
>


And the template 'table_filled_with_results' is defined as:

<table (tableAttributes) >

    <tr>
     (for each columnName in columns2use)
       <th>  [columnName]
     (end for)

  <dtml-in [query]>
    (for each columnName in columns2use)
     <tr> <td> <dtml-var [columnName]>
    (end for)
  </dtml-in>

</table>

How this _could_ work is as follows:

The template 'table_filled_with_results' gets evaluated _once_ when the the
document containing <dtml-component> is saved. This would produce the following
DTML:

<table width=100%>
    <tr>
       <th>  Name
       <th>  Age
  <dtml-in mySQLMeth>
     <tr> <td> <dtml-var Name>
             <td> <dtml-var Age>
  </dtml-in>
</table>

This is exactly what we want to use. During publishing, this DTML would be
evaluated as if it was included with a simple <dtml-var> instead of
<dtml-component>.
Also note that the above template cannot be defined in plain dtml. It would
need
special syntax since it itself is 'producing' DTML which later gets evaluated
at
publish time.

Cheers,
Shalabh