加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – Play中的部分视图存在吗?

发布时间:2020-12-16 19:10:21 所属栏目:安全 来源:网络整理
导读:我没有在Play Framework中发现任何部分视图的概念,类似于 Ruby on Rails的部分视图.例如,如果有布局/ main.scala.html布局: @(title: String)(content: = Html)(implicit flash: Flash)!DOCTYPE htmlhtml head title@title/title /head body section class=
我没有在Play Framework中发现任何部分视图的概念,类似于 Ruby on Rails的部分视图.例如,如果有布局/ main.scala.html布局:

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

    </head>
    <body>
        <section class="content">@content</section>
    </body>
</html>

还有layouts / _footer.scala.html“partial”,如何将_footer包含到main中?
Play中有类似内容吗?

解决方法

我认为RoR的部分观点过于复杂.关于Play模板要记住的事情,因为它们本质上只是可以直接从Scala代码调用的函数.而且,Play模板本质上是Scala代码.这意味着,可以从其他Play模板调用Play模板.因此,只需创建另一个名为footer.scala.html的模板,例如:

<footer>
   Powered by Play Framework
</footer>

然后从主模板中调用它,就像调用任何其他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>

不可能更容易.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读