Scala 部分观点是否存在?

Scala 部分观点是否存在?,scala,playframework,playframework-2.2,Scala,Playframework,Playframework 2.2,我在Play框架中没有发现任何类似于RubyonRails的部分视图的概念。例如,如果存在layouts/main.scala.htmllayout: @(title: String)(content: => Html)(implicit flash: Flash) <!DOCTYPE html> <html> <head> <title>@title</title> </head>

我在Play框架中没有发现任何类似于RubyonRails的部分视图的概念。例如,如果存在
layouts/main.scala.html
layout:

@(title: String)(content: => Html)(implicit flash: Flash)
<!DOCTYPE html>
<html>
    <head>
        <title>@title</title>

    </head>
    <body>
        <section class="content">@content</section>
    </body>
</html>
@(标题:字符串)(内容:=>Html)(隐式flash:flash)
@头衔
@内容
还有
layouts/\u footer.scala.html
“partial”,如何将
\u footer
包含到
main
中?
游戏中是否有类似的内容?

不确定您使用的是Play 1.x还是Play 2,但在Play 1中,有模板标记-请参见我认为RoR的局部视图过于复杂。关于Play模板需要记住的是,它们本质上只是可以直接从Scala代码调用的函数。而且,播放模板本质上是Scala代码。这意味着,可以从其他播放模板调用播放模板。因此,只需创建另一个名为
footer.scala.html
的模板,例如:

<footer>
   Powered by Play Framework
</footer>

由Play框架提供支持
然后从主模板调用它,就像调用任何其他Scala函数一样:

@(title: String)(content: => Html)(implicit flash: Flash)
<!DOCTYPE html>
<html>
    <head>
        <title>@title</title>
    </head>
    <body>
        <section class="content">@content</section>
        @footer()
    </body>
</html>
@(标题:字符串)(内容:=>Html)(隐式flash:flash)
@头衔
@内容
@页脚()

再简单不过了。

我想@Vidya想说的是,你可以这样做:

在main.scala.html中,我们添加了一个名为footer的html类型变量,默认值为空:

   @(title: String, footer: Html = Html(""))(content: Html)

    <!DOCTYPE html>

    <html>
        <head>
            <title>@title</title>
        </head>
        <body>
            @content
            @footer
        </body>
    </html>
@(标题:字符串,页脚:Html=Html(“”)(内容:Html)
@头衔
@内容
@页脚
然后在index.scala.html这样的页面中,我们可以执行以下操作:

@(message: String)

@footer = {
    <footer>the footer!</footer>
}

@main("Welcome", footer) {
    the content!
}
@(消息:字符串)
@页脚={
页脚!
}
@主(“欢迎”,页脚){
内容!
}

Play如何知道@footer是在哪里定义的?@Alex在本例中,
@footer
必须在
views.html
命名空间中定义,该命名空间将自动导入Play模板。如果它改为位于
app/views/common/footer.scala.html
,则它将改为
common.footer()