Skip to content

Instantly share code, notes, and snippets.

@brock
Last active July 31, 2017 12:58
Show Gist options
  • Save brock/a53c285c8cb5927d25aa to your computer and use it in GitHub Desktop.
Save brock/a53c285c8cb5927d25aa to your computer and use it in GitHub Desktop.
Play Framework Template Cheat-Sheet

Play Framework

Cheat Sheet for View Template Variables

Inside of a file like index.scala.html, you may want to get or set variables between Scala and JavaScript. Here are some examples.

set a scala variable

@test = { "something" }

set a scala variable by evaluating a scala expression (this example would return true if logged in)

@test = @{ 
	user.isDefined
}

set a javascript variable by parsing json from a scala variable

var data = @Html(Json.stringify(Json.toJson(data)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment