I\'d like to return a .js file from a template in Play!Framework 2.
Here\'s how I did that :
In my views folder, I created a template file :
You can have a scala.js
file but you don't call it with views.js.initials.render()
but instead js.initials.render()
At least with Scala it works with Play 2.2
This is possible by placing a route to the particular asset in your routes definition.
ie. GET /assets/javascripts/initials.js controllers..initials()
You did nothing wrong, Play allows you tu use only .html
, .xml
or .txt
extensions for views, so you need to use one of them.
From technical point of view it doesn't matter which one you'll use, anyway you need to return it from controller as JavaScript, ie with:
public static Result initials() {
return ok(views.html.initials.render()).as("application/javascript");
}