Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 在播放2视图中作为模板参数的模板_Scala_Playframework_Playframework 2.1 - Fatal编程技术网

Scala 在播放2视图中作为模板参数的模板

Scala 在播放2视图中作为模板参数的模板,scala,playframework,playframework-2.1,Scala,Playframework,Playframework 2.1,我想在play 2中定义一些模板,这些模板将另一个模板作为参数: @aTemplate(otherTemplate()) 我认为这在scala应该是可能的,对吧 otherTemplate中的参数定义看起来如何?我也应该有一个默认值。我在想这样的事情: @(template: PlayScalaViewTemplate = defaultTemplate()) 谢谢 是的,你可以。一旦您发现播放模板只是函数,它就变得非常简单了 将简单模板作为参数获取的高阶模板如下所示: higherOrde

我想在play 2中定义一些模板,这些模板将另一个模板作为参数:

@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>