Search code examples
.netvb.netvelocitynvelocity

NVelocity macro parameter not evaluating


I'm looking to create an inline function (method) inside my NVelocity template. The solution to this appears to be to use Velocimacros. So, I mocked up the following template to test:

#macro( getOutput $one $two $three )
<td>$one</td>
<td>$two.Item2</td>
<td>$three</td>
#end

<table>
#foreach( $item in $mdl.Items )

    <tr>
        #set( $one1 = $item.Item1 )
        #getOutput( $one1 $item $item.Item3 )  ## item.Item3 won't evaluate!
    </tr>

#end
</table>

$mdl is my base Model object, which for this example contains one property, Items, which is a List(Of Tuple(Of String, Integer, Date)). Populated with test data like so:

Dim items As New List(Of Tuple(Of String, Integer, DateTime))
With items
   .Add(New Tuple(Of String, Integer, DateTime)("One", 1, #1/1/2001#))
   .Add(New Tuple(Of String, Integer, DateTime)("Two", 2, #2/2/2002#))
   .Add(New Tuple(Of String, Integer, DateTime)("Three", 3, #3/3/2003#))
End With

When I run the template, the problem I'm having is that the output from the macro parameter $three is literally "$item.Item3" instead of evaluating to #3/3/2003#. (BTW - this happens with any of the 3 items in the tuple if they are passed with the .Item call, so it isn't about the data type).

I can make a variable and pass it just fine ($one1). I can pass the tuple itself and call the .Item property inside the macro ($item.Item2), but for some reason I cannot call the .Item property when passing the argument to the macro. Any insight?


Solution

  • It looks like NVelocity macro support is limited.

    http://www.castleproject.org/others/nvelocity/problems.html#macros

    An alternative would be to use Helpers:

    NVelocity extension method ASP.NET webform