For me, this is suitable as an answer, at least for the last question.
It is just scala. Just the built-in magic of XML.
http://www.alvarocarrasco.com/2011/03/play-framework-and-templating-with.html?m=1
Example:
This is the template : Templates.scala file
package templates import play.api.templates.Html import scala.xml.Xhtml import controllers.routes object Main { def page (title:String="Default title")(content: => scala.xml.Elem) = Html { "<!DOCTYPE html>" + Xhtml.toXhtml( <html> <head> <title>{title}</title> <link rel="stylesheet" media="screen" href={routes.Assets.at("stylesheets/main.css").toString()} /> <link rel="shortcut icon" type="image/png" href={routes.Assets.at("images/favicon.png").toString()} /> <script src={routes.Assets.at("javascripts/jquery-1.9.0.min.js").toString()} type="text/javascript" /> </head> <body> {content} </body> </html> ) } // a panel template, just as an example def panel (label:String="Some label")(content: => scala.xml.Elem) = { <div class="panel"> <div class="panel-label">{label}</div> <div>{content}</div> </div> } }
This is the index.scala file index page .
package views import templates.Main._ object IndexPage { def apply() = { page(title="Welcome to my Page!") { <div> <h1>Hello</h1> <p>Some template markup</p> { panel(label="Dashboard panel")( <div> Panel content </div> ) } </div> } } }
This is the controller: Application.scala File
package controllers import play.api.mvc._ object Application extends Controller { def index = Action { Ok( views.IndexPage() ); } }
source share