在Play Framework视图模板中包含纯HTML页面 [英] Include plain HTML page inside a Play Framework view template

查看:137
本文介绍了在Play Framework视图模板中包含纯HTML页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Play Framework的视图模板中包含一个纯HTML页面?我有一个场景,其中有一个共同的视图模板,并在模板的主体,我想包括某些静态html页面。我知道我可以在特定模板中包含其他模板,但是我不确定是否可以包含一个纯HTML页面? 解决方案

其中一个选择是使您的静态HTML成为模板,例如,创建 myStaticPage.scala.html

 < h1>静态页面< / h1> 
< p>此网页是静态的,但它仍然是一个模板。< / p>

然后您的视图模板myView.scala.html:

  @(staticPage:Html)

< html>
< head> ...< / head>
< body> @ staticPage< / body>
< / html>

然后在您的动作中呈现模板:

  def renderMyStaticPage =动作{
Ok(views.html.myView(views.html.myStaticPage())
}

您只需确保您的HTML页面能够转义任何 @ 符号另一方面,如果包含的HTML页面更具动态性,那么只需加载 @@



来自文件/数据库/类加载器的HTML /无论它来自哪里,例如:

  def renderMyStaticPage = Action {
val staticPage:String = //在这里加载静态页面的代码
Ok(views.html.myView(Html(staticPage))
}


Is there a way to include a plain html page inside a Play Framework's view template? I have a scenario wherein there is a common view template and in the body of the template, I would like to include certain static html pages. I know that I can include other templates inside a certain template, but I'm not sure if I could include a plain html page?

解决方案

One option is to just make your static HTML a template, eg, create myStaticPage.scala.html:

<h1>Static page</h1>
<p>This page is static, though it is still a template.</p>

Then your view template, myView.scala.html:

@(staticPage: Html)

<html>
  <head>...</head>
  <body>@staticPage</body>
</html>

And then in your action that renders the template:

def renderMyStaticPage = Action {
  Ok(views.html.myView(views.html.myStaticPage())
}

You just need to make sure that your HTML page escapes any @ symbols with @@.

On the other hand, if which HTML page that's being included is more dynamic, then simply load the HTML from the file/database/classloader/whereever it's coming from, eg:

def renderMyStaticPage = Action {
  val staticPage: String = // code to load static page here
  Ok(views.html.myView(Html(staticPage))
}

这篇关于在Play Framework视图模板中包含纯HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆