Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Play 2.x + SBT + Scala + Jade
All you need to do is,
In your SBT Dependencies add,
"de.neuland" % "jade4j" % "0.3.11" from "",
"com.googlecode.concurrentlinkedhashmap" % "concurrentlinkedhashmap-lru" % "1.3.1",
"org.apache.commons" % "commons-jexl" % "2.1.1"
You need apache libs as Jade4J uses them internally,
Create a file called JadeController.scala
import de.neuland.jade4j.Jade4J
import de.neuland.jade4j.JadeConfiguration
import de.neuland.jade4j.template.FileTemplateLoader
import de.neuland.jade4j.template.JadeTemplate
import play.api.mvc.Controller
import play.api.templates.Html
import scala.collection.JavaConversions._
trait JadeController extends Controller {
val jadeConfig = new JadeConfiguration
val templateLoader = {
jadeConfig.setTemplateLoader(new FileTemplateLoader("app/views/", "UTF-8"))
def render(template: String): Html = {
render(template, Map[String, String]())
def render(template: String, context: Map[String, Object]): Html = {
try {
val jadeTemplate: JadeTemplate = jadeConfig.getTemplate(template)
new Html(new StringBuilder(jadeConfig.renderTemplate(jadeTemplate, context)))
catch {
case ex: IOException => {
println("Missing file exception")
return new Html(new StringBuilder)
This will take care of the rendering,
and then in your controller,
object Application extends JadeController {
def index = Action {

lowi commented Aug 14, 2014

For play framework 2.3, replace:
import play.api.templates.Html =>
import play.twirl.api.Html
import play.twirl.api.HtmlFormat

new Html(new StringBuilder(jadeConfig.renderTemplate(jadeTemplate, context))) =>
Html.apply(new StringBuilder(jadeConfig.renderTemplate(jadeTemplate, context)).toString())

return new Html(new StringBuilder) =>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment