Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I render a simple html page using play framework?

Is it a way to render a pure html file with play framework version 2? I don't want to put it in public/ folder because later on there will be some dynamic information added to it.

like image 301
nightograph Avatar asked Jun 20 '12 19:06

nightograph


2 Answers

Here is my solution:

in routes: I do some configurations as following.

GET     /hello.html                 controllers.Assets.at(path="/public/html", file="hello.html")
GET     /public/javascripts/jquery-1.9.0.min.js     controllers.Assets.at(path="/public/javascripts", file="jquery-1.9.0.min.js")
GET     /public/stylesheets/bootstrap.css           controllers.Assets.at(path="/public/stylesheets", file="bootstrap.css")

and then the file structure is as below:

public->HTML->hello.html
public->javascripts->jquery-1.9.0.min.js
public->stylesheets->bootstrap.css

for hello.html , here is its content.

<!DOCTYPE html>    
<html lang="en">
<head>
    <meta charset="utf-8">
    <link rel='stylesheet' type='text/css' href='/public/stylesheets/bootstrap.css'>
</head>    
<body>
    <script src="/public/javascripts/jquery-1.9.0.min.js" type="text/javascript"></script>
</body>
</html>

After these three steps, you can use outside HTML directly. No need to follow Play template to do front-end development work. So now, Play only is responsible for back-end. Front-end developer only needs to operate this public file to do development.

like image 52
Haimei Avatar answered Oct 04 '22 22:10

Haimei


Of course, put your whole static html ie. in index.scala.html and use simplest possible way:

public static Result index(){
    return ok(index.render());
}

That are the basics, you should go trough Play's documentation and samples

like image 34
biesior Avatar answered Oct 04 '22 21:10

biesior