Skip to content

Instantly share code, notes, and snippets.

@eishay
Created March 22, 2012 06:29
Show Gist options
  • Save eishay/2156645 to your computer and use it in GitHub Desktop.
Save eishay/2156645 to your computer and use it in GitHub Desktop.
//current is a reference to the Application object
import play.api.Play.current
object Templates extends Controller {
//name is the template name
//callback is the jQuery jsonp function name as in jQuery17104730278281494975_1332396095851
def load(name: String, callback: String) = Action { request =>
val path = current.getFile("/templates/%s.handlebars.html".format(name));
val content = Files.readFile(path)
//making the file content javascript ready
val escaped = content.replace("\"", "\\\"").replace("\n", "\\n\\\n")
//making the escaped content jsonp ready as in jQuery17104730278281494975_1332396095851("<div id=\"q ....
Ok("""%s("%s")""".format(callback, escaped))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment