Scala 在播放2视图中作为模板参数的模板
我想在play 2中定义一些模板,这些模板将另一个模板作为参数:Scala 在播放2视图中作为模板参数的模板,scala,playframework,playframework-2.1,Scala,Playframework,Playframework 2.1,我想在play 2中定义一些模板,这些模板将另一个模板作为参数: @aTemplate(otherTemplate()) 我认为这在scala应该是可能的,对吧 otherTemplate中的参数定义看起来如何?我也应该有一个默认值。我在想这样的事情: @(template: PlayScalaViewTemplate = defaultTemplate()) 谢谢 是的,你可以。一旦您发现播放模板只是函数,它就变得非常简单了 将简单模板作为参数获取的高阶模板如下所示: higherOrde
@aTemplate(otherTemplate())
我认为这在scala应该是可能的,对吧
otherTemplate中的参数定义看起来如何?我也应该有一个默认值。我在想这样的事情:
@(template: PlayScalaViewTemplate = defaultTemplate())
谢谢 是的,你可以。一旦您发现播放模板只是函数,它就变得非常简单了 将简单模板作为参数获取的高阶模板如下所示: higherOrder.scala.html: 结果将是:
<html>
<head><title>Page</title></head>
<body>
<div>
<p>This is the template</p>
<p>This is rendered within the template passed as parameter</p>
</div>
</body>
</html>
因此,scala模板最终是函数,所以您可以像函数一样组合它们。是的,您可以。一旦您发现播放模板只是函数,它就变得非常简单了 将简单模板作为参数获取的高阶模板如下所示: higherOrder.scala.html: 结果将是:
<html>
<head><title>Page</title></head>
<body>
<div>
<p>This is the template</p>
<p>This is rendered within the template passed as parameter</p>
</div>
</body>
</html>
因此,scala模板最终是函数,因此您可以像函数一样组合它们。嘿,谢谢!我也找到了Html参数类型,但是如何为simple.scala.Html定义默认函数/内容:Html?我不知道你的意思。模板生成具有apply方法的类,该方法接收模板所需的参数。嘿,谢谢!我也找到了Html参数类型,但是如何为simple.scala.Html定义默认函数/内容:Html?我不知道你的意思。模板生成具有apply方法的类,该方法接收模板所需的参数。
def index = Action {
Ok(views.html.higherOrder(html => views.html.simple(html)))
}
<html>
<head><title>Page</title></head>
<body>
<div>
<p>This is the template</p>
<p>This is rendered within the template passed as parameter</p>
</div>
</body>
</html>