Playframework 2.1 Japid global variable

124 views Asked by At

May i know how to init global variables in play framework? if can show in Japid is the best.

Appreciate your help.

Thanks

1

There are 1 answers

0
A1ucard On

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.