4

I'm migrating an Play 2.4 application to 2.5 and now play.Play.application().isProd is deprecated. I use this in various places in scala.html templates. (To decide weather or not to use minimized javascript.)

It seems unreasonable to pass this in as parameters into every template.

Is there a way to inject the Application into the template directly?

Sindri Traustason
  • 4,985
  • 5
  • 44
  • 63
  • 1
    Play 2.6 will introduce template constructors. https://www.playframework.com/documentation/2.6.x/ScalaTemplates#Template-constructor – danielnixon Mar 15 '17 at 23:33

1 Answers1

-1

I used the same method in 2.4, in 2.5 I switched to play.Environment.simple().isProd

Gus
  • 4,058
  • 2
  • 22
  • 27
  • -I'm pretty sure you should be using `play.Environment.underlying().isProd` according to the javadoc in `Environment`, `simple()` is always in test mode.- Disregard that, underlying is not a static method. But still, I don't think simple is the correct choice here. – Sindri Traustason Mar 18 '16 at 11:00
  • You're right, I just tested and simple() always returns test mode. I love that those guys just deprecate everything but don't tell what to use instead... – Gus Mar 18 '16 at 14:45
  • They do tell you to use an injected Application or Environment in the deprecation comment. However as far as I can tell injection is not possible in the templates. – Sindri Traustason Mar 18 '16 at 15:15
  • 2
    I started a thread about this on the google groups, but I still didn't get a solution: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/play-framework/wu1SFlndtRQ – Gus Mar 21 '16 at 10:30