我将 Scalatra 与 Scalate 和 Jade 一起使用。当我尝试应用一个接受值的模板时,这些值并没有被应用到模板上,我得到一个 NoValueSetException ......这是我拥有的代码:
// --------- In PostsServlet ------------------
get("/:page") {
/*
val page:Int = params.getOrElse("page", "1").toInt
val posts = PostCollection.page(page)
*/
contentType="text/html"
jade("/index.jade", "foo" -> "bar")
}
// ------------------ In index.jade ----------------------
-@ var foo : String
-attributes("title") = "Circuits Of Imagination"
-attributes("headline") = "Writings"
和例外:
The value for 'foo' was not set
org.fusesource.scalate.NoValueSetException: The value for 'foo' was not set
at org.fusesource.scalate.RenderContext$$anonfun$attribute$1.apply(RenderContext.scala:159)
at org.fusesource.scalate.RenderContext$$anonfun$attribute$1.apply(RenderContext.scala:159)
at org.fusesource.scalate.RenderContext$class.attributeOrElse(RenderContext.scala:167)