Reputation: 199
May i know how to init global variables in play framework? if can show in Japid is the best.
Appreciate your help.
Thanks
Upvotes: -1
Views: 122
Reputation: 199
I found the solution. Below is my example:
I create a class and extends to Action.Simple
package common;
import play.Play;
import play.mvc.Action;
import play.mvc.Http.Context;
import play.mvc.Result;
public class Init extends Action.Simple{
@Override
public Result call(Context ctx) throws Throwable {
ctx.args.put("resourcesurl", Play.application().configuration().getString("resources.url"));
return delegate.call(ctx);
}
}
and this is my controller:
@With(Init.class)
public class Museum extends JapidController{
public static Result nes(){
return renderJapid();
}
}
at my html:
<img src="${Context.current().args.get("resourcesurl")}/resources/test.jpg"/>
hope this help others as well.
Upvotes: 0