【问题标题】:Castle NVelocity Including Variables not Variable contentsCastle NVelocity 包括变量而不是变量内容
【发布时间】:2010-02-02 16:41:32
【问题描述】:

我正在使用 Castles 的 NVelocity 引擎来做一些模板工作。这就是问题所在。我的几个模板工作正常,但其中一个不是。

#foreach($i in $Items)
<div class="grid_3 folioItem"> <a rel="prettyPhoto[portfolio]" href="$i.Link" class="lightBox"><img src="$i.Image" width="220" height="125" alt="showcase" /></a>
  <h4>$i.ShortName</h4>
  <p>$i.LongName</p>
  <p><a class="button pngFix" href="$i.Link">$i.LinkText</a></p>
</div>
#end

由于某种原因,上面的代码工作了一半。我得到了六组带有所有内脏的 div 标签,但是 Velocity 输出 $i.ShortName 而不是 $i.ShortName 上的内容。任何线索这是为什么?如果我得到六个输出,这会让我相信 Items 设置正确并且存在于 Velocity Template 中。但出于某种奇怪的原因,孩子们不会。

现在 Items 是 List&lt;CategoryItem&gt;,我反复检查以确保我没有拼错成员的名字。

我错过了什么?

【问题讨论】:

  • 举个例子,我得到的是

    $i.LongName

    而不是

    This is a Long Name

标签: velocity castle-monorail nvelocity


【解决方案1】:

好的。所以我想通了(我认为)子对象似乎只会将它们的属性暴露给模板。例如:

public class Item{
   public string BadName;
   public stirng GoodName {
       get {
           return "Foo"
       }
   }
}

模板中可以引用GoodName,但BadName不能

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 2019-12-30
  • 1970-01-01
  • 2017-03-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多