有没有办法在 Play Framework 的 View 模板中包含纯 html 页面?我有一个场景,其中有一个通用 View 模板,在模板的主体中,我想包含某些静态 html 页面。我知道我可以在某个模板中包含其他模板,但我不确定是否可以包含纯 html 页面?
最佳答案
一个选择是让你的静态 HTML 成为一个模板,例如,创建 myStaticPage.scala.html
:
<h1>Static page</h1>
<p>This page is static, though it is still a template.</p>
然后是你的 View 模板,myView.scala.html:
@(staticPage: Html)
<html>
<head>...</head>
<body>@staticPage</body>
</html>
然后在呈现模板的操作中:
def renderMyStaticPage = Action {
Ok(views.html.myView(views.html.myStaticPage())
}
您只需确保您的 HTML 页面使用 @@
转义任何 @
符号。
另一方面,如果被包含的 HTML 页面更动态,那么只需从文件/数据库/类加载器/无论它来自哪里加载 HTML,例如:
def renderMyStaticPage = Action {
val staticPage: String = // code to load static page here
Ok(views.html.myView(Html(staticPage))
}
关于html - 在 Play Framework View 模板中包含纯 HTML 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20873866/