cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leszek Gawron <>
Subject Re: [RT] Attribute Driven Templates (Was: [RT] do me a favor, don't call them taglibs)
Date Sat, 04 Dec 2004 17:58:28 GMT
Daniel Fagerstrom wrote:
> macro(<name>,<param-name>,...,<param-name>)
> -------------------------------------------
> example:
> <table do="macro(mytable,list,td-class)">
>   <tr do="forEach($list)">
>     <td class="${$class}">${item}</td>
>   </tr>
> </table>
> We also need an evalBody as in JXTG. And maybe we should have a 
> possibilty to give a name space to the macro name.
We also need:
- some script compiler directives i.e. for cache control (as in JXTG)
- template inclusion so the templates may be defined in a separate file

Named macros rock! This way we can completely eliminate the need for 
this hack:

Imagine that user wants to render a fancy table providing only a header 
rendering macro and a row template:

<tr do="macro(tableHeader,context)">

<tr do="macro(singleRow,context)">

<table do="macro(mytable,list,headerMacro,rowMacro)">
   <!-- some fancy longish code here -->
     <th do="eval($headerMacro)"/>
   <tr do="forEach($list)">
     <td do="eval($rowMacro,context=.)"/><!-- problem here -->


Still I see one problem: as every directive is bound to some tag one 
should be able to eval the macro and strip the root element. In my case 
the output would look like this:


This would fix it: <th do="eval($headerMacro,stripRoot=true)"/>

If we used tags we would be able to introduce <jx:template> as in jxtg 
that would not show up in the output. Here we have no such possibility.

> Several directives
> ------------------
> So, how do we handle multiple directives for one element? We could 
> handle the TAL example above like:
> <p 
> do="let(x=/a/long/path/from/the/root;if(x);content(x/txt);attributes(class=x/class)">

IMO this one is not that clear as the same syntax using tags. This will 
be also a lot harder to implement as we will have to create much more 
sophisticated parser. With tags, the xml syntax does 95% of parsing 
itself with only a little amount of additional coding.

> <jx:let name="x" value="/a/long/path/from/the/root">
>   <jx:if test="x">
>     <jx:content select="x/txt">
>       <jx:attribute name="class" value="x/class">
>         <p>Ex Text</p>
>       </jx:attribute>
>     </jx:content>
>   </jx:if>
> <jx:let>
What hits me is how the attribute based syntax can be compact comparing 
to this monster :)

> Formating?
> ----------
> IMO most of the basic formating can be done in a special conversion 
> layer as we have discussed in the convertor thread.
I understand this is completely orthogonal functionality to the one you 

> I have not given any detailed thought to all of the constructions above, 
> just wanted to concretize what attribute driven templating could look 
> like in Cocoon.
I am only afraid how I will explain the directive ordering to my 
developers. Moreover: how many mistakes they will make, which IMO will 
be much harder to trace comparing to old verbose syntax.

Leszek Gawron                            
Project Manager                                    MobileBox sp. z o.o.
+48 (61) 855 06 67                    
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

View raw message