用于调用带有评估参数的方法的 NVelocity 语法
我有一个相当简单的模板,我需要从中进行方法调用。但是,NVelocity 似乎并不评估本身就是 NVelocity 变量 的方法参数。采用以下 NVelocity 模板:
#if (--- CONDITION SNIPPED ---)
<blockquote class="column span-4">
I MADE IT!
</blockquote>
#else
<blockquote class="column span-4">
$extensionMethods.TestMethod(${var1})
</blockquote>
#end
在上面的模板中,$extensionMethods
作为类的实例传入,并且在传入计算值时效果非常好(例如 $extensionMethods.TestMethod(4)< /code> 每次都有效)。但是,使用
$var1
会导致整个字符串按原样返回:$extensionMethods.TestMethod(${var1})
。
有没有办法将变量延迟传递给方法以使上述模板正确评估?
I have a fairly simple template that I need to make a method call from. However, NVelocity does not seem to evaluate method parameters that themselves are NVelocity variables. Take the following NVelocity template:
#if (--- CONDITION SNIPPED ---)
<blockquote class="column span-4">
I MADE IT!
</blockquote>
#else
<blockquote class="column span-4">
$extensionMethods.TestMethod(${var1})
</blockquote>
#end
In the above template, $extensionMethods
is passed in as an instance of a class and works wonderfully when passing in evaluated numbers (e.g. $extensionMethods.TestMethod(4)
works every time). However, using $var1
causes the entire string to be returned as-is: $extensionMethods.TestMethod(${var1})
.
Is there a way to pass in a variable to a method lazily to get the above template to evaluate correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您遇到问题,可能与您的变量类型或方法可用性有关。我已经构建并测试了以下内容:
和我的模板:
和输出:
我们可以看到您的扩展方法的一些代码吗?
If you are having trouble, it's likely to be something to do with your variable types, or the method availability. I've built and tested the following:
And my template:
And the output:
Can we see some code for your extension methods?