Play 2.0 And Scalate Step-By-Step
Jan Helwich has done a great job of describing how to use Scalate with Play 2.0. He’s even provided an example Play 2.0 project which uses Scalate. This post contains step-by-step instructions for a new project based on his work.
For convenience, I’ve also wrapped these changes up as a patch that can be applied to a new Play 2.0 project. Apply it with git am --signoff play20-with-scalate.patch
.
Create a new Play project.
play new myproject # choose "1 - Create a simple Scala application"
Add Scalate to your project dependencies in
project/Build.scala
val appDependencies = Seq( // Add your project dependencies here, "org.fusesource.scalate" % "scalate-core" % "1.5.3" )
Place a copy of Jan Helwich’s
ScalateIntegration.scala
inapp/lib
curl -o app/lib/ScalateIntegration.scala https://raw.github.com/janhelwich/Play-2-with-Scala-and-Scalate/master/app/controllers/ScalateIntegration.scala
Set the default Scalate template type in
conf/application.conf
.# Default Scalate template format (mustache, scaml, jade, ssp) scalate.format=jade
Create a layout and a template.
app/views/layouts/default.jade
-@ var body: String
-@ var title: String = "Page"
!!!5
html
head
title= title
body
!= body
app/views/index.jade
-@ var title: String = "Page"
h1= title
Use your templates in a controller.
package controllers import play.api._ import play.api.mvc._ object Application extends Controller { def index = Action { Ok(Scalate("index.jade").render('title -> "Hello world!")) } }
Done! Try out your app with play run