kes kes - 3 months ago 18
Scala Question

How to detect application mode in Play 2.x

From within a Play 2.1 application, how would I programmatically determine which mode the application is running in (i.e., Development vs. Production)?

For example, it would be useful to be able to do something like this from inside a template:

<p>@if(__some_play_API_call__ == Dev) { <b>Development mode</b> }</p>


In the Play 2.0 API documentation, there appears to be a
mode
property of the
play.api.Application
class... however, I am unsure about how to get at the instance of the currently running application.

Answer

You can access the current Appliction via

play.api.Play.current()

to find out the mode try

play.api.Play.current().mode()

or simply use

play.api.Play.isDev(play.api.Play.current())
Comments