16.03.2012

Play 2.0 released - first impressions from the 1.2 perspective

Play 2.0 is here! What does this mean for the Joe Average Play 1 developer?

After the download from http://download.playframework.org/releases/play-2.0.zip is installed as usually, I rename the /play script to /play20 to ensure using the right version.
Projects done with release candidates of Play 2.0 have to be upgraded by changing the last line of /project/plugins.sbt:
addSbtPlugin("play" % "sbt-plugin" % "2.0")
Below you find a number of snippets you may find helpful:
  • Iterate over collection
    • Play1: #{list items:collection, as:'var' } ...$var...    #{/list}
    • Play2: @for(var <- collection) { ... @var ... }
  • Insert relative URL in template:
    • Play1: @{controller.method}
    • Play2: @routes.Controller.method()
  • Insert absolute URL in template:
    • Play1: @@{controller.method}
    • Play2: http://@request.headers().get("HOST")@routes.Controller.method()
  • URL to file in public:
    • Play1: @{'/public/images/logo_16x16.png'}
    • Play2: @routes.Assets.at("images/logo_16x16.png")
Want to add a snippet? - Great! - Send me a comment!


EDIT: This went into the play 2.0 wiki: https://github.com/playframework/Play20/wiki/Play-2.0-for-Play-1.x-developers