NVelocity宏参数未评估

| 我正在寻找在我的NVelocity模板中创建一个内联函数(方法)的方法。解决方案似乎是使用Velocimacros。因此,我模拟了以下模板进行测试:
#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
是我的基本Model对象,在本示例中,该对象包含一个属性
Items
,即property3ѭ。像这样填充测试数据:
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
当我运行模板时,我遇到的问题是宏参数
$three
的输出实际上是\“ $ item.Item3 \”,而不是评估为#3/3/2003#。 (顺便说一句,如果通过
.Item
调用传递了元组中的3个项目中的任何一个,则会发生这种情况,因此与数据类型无关)。 我可以创建一个变量并将其传递给它($ one1)。我可以传递元组本身,并在宏($ item.Item2)中调用.Item属性,但是由于某些原因,在将参数传递给宏时,我无法调用
.Item
属性。有见识吗?     
已邀请:
        看来NVelocity宏支持有限。 http://www.castleproject.org/others/nvelocity/problems.html#macros 一种替代方法是使用助手: NVelocity扩展方法ASP.NET Webform     

要回复问题请先登录注册