velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aapo Laakkonen" <aapo.laakko...@giro.fi>
Subject RE: Variable method name in a macro?
Date Tue, 08 Oct 2002 12:57:56 GMT
>> So, similar to what Aapo is after
>>
> Does this do what you want...
> 
> #set ($pre = '$book.')
> #set ($bookeval = "$pre$propertyName")
> $took.eval($bookeval)

Ok. I got it to work!

I have attached my solution in this posting.

And here is how to use it:

#macro(list $data $columns)
<table border="1">
<tr>
    #foreach($column in $columns)
    <th>$column</th>
    #end
</tr>
#foreach($row in $data)
<tr>
    #set ($table = '$row.')
    #foreach($column in $columns)
        <td>$Global.evaluate("$table$column")</td>
    #end
</tr>
#end
</table>
#end

#set($columns = ["name.first", "name.last"])
#list($employees $columns)

And this renders to something like this:

|----------------|----------------|
|   name.first   |    name.last   |
|----------------|----------------|
| Aapo           | Laakkonen      |
|----------------|----------------|

Next I can i18n name.first and name.last headings and continue to add
mopre functionality.

Thanks for your help!

Mime
View raw message