In Play! 2.0, one can use Global
as documented here. Global
needs to be in the default (empty) package.
I also need globals in my application, and some of them need to be available to the methods in Global
. Thus, I put them in Global.scala like so:
package object globals {
lazy val foo = Play.maybeApplication.flatMap(_.configuration.getString("foo")).getOrElse("default_value_of_foo")
}
And then I use it in my controllers like this:
globals.foo
Is there a better way?