Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include plain HTML page inside a Play Framework view template

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?

like image 791
joesan Avatar asked Jun 26 '26 00:06

joesan


2 Answers

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))
}
like image 106
James Roper Avatar answered Jun 28 '26 12:06

James Roper


You could.

Just put something like that in your routes file:

GET /file   controllers.Assets.at(path="/public", file="html/file.html")

Here is a duplicated post: Route to static file in Play! 2.0

like image 29
Christian Schmitt Avatar answered Jun 28 '26 14:06

Christian Schmitt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!