play.api.Configuration.getBoolean() returns Option[Boolean] . In the game template engine, an Option containing Some(...) will always be evaluated as true in the if condition, even if the option contains Some(false) .
As a test, I created all the possible values โโfor Option[Boolean] and checked what happened to them inside @if(...) in the template.
Controller:
object Application extends Controller { def index = Action { val a: Option[Boolean] = None val b: Option[Boolean] = Some(true) val c: Option[Boolean] = Some(false) Ok(views.html.index(a, b, c)) } }
Template:
@(a: Option[Boolean], b: Option[Boolean], c: Option[Boolean]) @if(a) { a } @if(b) { b } @if(c) { c }
Performing this task gives the result "bc".
If your configuration parameter has a default value, get getOrElse parameter getOrElse :
Play.current.configuration.getBoolean("system.debugMode").getOrElse(defaultValue)
If you are sure that the configuration parameter will always be there (or you are satisfied that your template reports that the debugging mode is disabled if the parameter is not set), you can also flatten :
Play.current.configuration.getBoolean("system.debugMode").flatten
source share