velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rene Parra <rxpa...@yahoo.com>
Subject Re: Velocimacro argument (by-name) passing
Date Mon, 19 Jul 2004 18:38:57 GMT
This is primarily resulting from a need to "componentize" my UI.
There are several pages that re-use the same structure, but vary in content.
I might have #content1() on one page, and #content2() on the other, but they might all share
the same structure.  Also, the #content() may need page-supplied, variations that are not
common across all features.  For example I might have something like the following:
 
#myHeader()
  <th>header1</th>
  <th>header2</th>
#end
 
#myRow($row)
  <td>$row.property1</td>
  <td>$row.property2</td>
#end
 
<form ...>
  #renderTable("#myHeader()" "#myRow($row)")
</form>
 
 
Note that in this example #myRow() takes an argument that only makes sense
within the macro #renderTable.
 
I agree that this is a little complex for templates, but this sort of thing would look very
simple in JSP Tags:
 
<mytlib:form ...>
  <mytlib:table  rowvar="row">
     <mytlib:tableheader>
          <th>header1</th>
          <th>header2</th>
     </mytlib:tableheader>
     <mytlib:tableheader>
     </mytlib:tablerow>
          <td>${row.property1}</td>
          <td>${row.property2}</td>
     </mytlib:tablerow>
  </mytlib:table>
</mytlib:form>

Nathan Bubna <nathan@esha.com> wrote:


> The only solution that I have found is to create a macro for each "deferred
content".
> For example:
>
> #macro (bolddiv1)
> #bold( "$innerVar hello - 1st div")
> #end
>
> #macro (bolddiv2)
> #bold( "$innerVar hello - 2st div")
> #end
>
> #reusableStruct( "#bolddiv1()" "#bolddiv2()")
>
> This gives me the most readability without sacrificing flexibility in
> terms of argument-evaluation deferrment.
>
> Any drawbacks to this approach?

hmm. i dunno, i haven't done this sort of thing (at least not to this
degree). a bit too complex for my tastes. my only suggestion would be to pay
attention to your velocity.properties configuration w.r.t. velocimacros
(libraries, overridability, global/local, etc.) to avoid needless
inefficiency.


		
---------------------------------
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message