【发布时间】:2014-05-07 12:13:22
【问题描述】:
我试图让 Play 布局更加动态,但不知道如何,有什么帮助吗??
我的问题是这样的:
index.scala.html
@(title: String,templateName:String) // templateName is data obtained from a db src,
@templates.(@templateName)(title,templateName){ // I wanted to put value of templateName after @template.****, so that template names get set at compile time, but of course it gives out errors
}
内部视图 -> 模板 -> main.scala.html, foo.scala.html, bar.scala.html
我并不是说我需要动态地制作整个“主布局”,而是动态地获取名称。可以吗?
我尝试像下面那样做,但我需要知道每个templates name,任何建议
index.scala.html
@(title: String,templateName:String)
@if(templateName == "foo"){
@templates.foo(title,templateName){
}
}
else if(templateName == "bar"){
@templates.bar(title,templateName){
} else {
......
}
我想我没有正确解释我的问题:
@johanandren
嗯,好像有什么误会。是的,我现在明白了,我不能从控制器中动态地 (if reflection isn't used, and it seems to have its own cons as well,thanks to you and @Khanser)提供模板名称,而我根本没有打算这样做。
但是就像你说的“如果你只是想在你的个人子模板周围应用通用模板”,我主要担心的是我不会有一个通用模板 ,正如您所说,实际上基于用户 => 不同的 主模板。是的,我可以将开关/案例用于我的目的,但我需要知道 * 模板名称并将它们硬编码在每个子模板上。
是的,我已经理解了“templates->main.scala.html”和“sub-templates=>index.scala.html”等的使用……以及注入子模板主模板上的。我想我已经这样做了invert the template flow。
【问题讨论】:
标签: scala playframework-2.2 scala-template