Render a Play!Framework2 javascript as template?

后端 未结 3 1953
攒了一身酷
攒了一身酷 2021-01-07 03:00

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 :

         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-07 03:41

    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");
    }
    

提交回复
热议问题