Search code examples
templatesplayframeworkhttp-status-code-404

Load data in renderArgs for 404 & 500 errors


Using Play Framework, I was wondering if it was possible to load some vars in the template like I do in other controllers.

I mainly think about my "STATIC_URL" var that contains the path to the static files, that changes between my DEV/PROD modes.

Or at least, which alternatives I can use to make this works?


Solution

  • Your question is not very clear and could do with an example of what you are trying to achieve. However if what I think you are asking is correct try the following in your controller:

    //This will run before any controler request is called
    @Before
    static void globals() {
        renderArgs.put("staticUrl", staticUrl);//Adds staticUrl object to the renderArgs map.
    }
    

    Then in your template use ${staticUrl} to access the value from the renderArgs map.