Home

Awesome

This code is not anymore actively maintained

I don't have time anymore to maintain this project. If you still use it, and want or need it for your projects, I will be happy to point to your updated fork.

If you don't absolutely need the groovy templates though I would recommend to use the Twirl templates which are type-safe and compiled. This project was just intended as a bridge between Play 1 and Play 2 to simplify the migration.


Groovy templates for Play! 2

Groovy template mechanism for Play! 2, to make the migration between Play 1 and Play 2 easier. The template engine is based on the one of Play 1.

More information and documentation about the template engine can be found here:

In order to use the plugin, make sure you have these dependencies / resolvers in your SBT build:

In order for pre-compilation to work correctly in PROD mode, you need to hook the groovy templates plugin in the sourceGenerators of your build, for example:

import eu.delving.templates.Plugin._

val main = PlayProject(appName, appVersion, appDependencies, settings = Defaults.defaultSettings ++ groovyTemplatesSettings).settings(

  sourceGenerators in Compile <+= groovyTemplatesList,

)

And your project/plugins.sbt needs to contain the Groovy Templates SBT plugin:

resolvers ++= Seq(
   "Sonatype OSS Repository" at "https://oss.sonatype.org/content/groups/public"
)

addSbtPlugin("eu.delving" %% "groovy-templates-sbt-plugin" % "1.6.4-SNAPSHOT")

(note: this will scan for templates at compilation time and generate a list which is included in the build and used in PROD mode to pre-compile the templates. We need this because Groovy Templates aren't compiled source-files)

Disabling the reloading of the application when a template file is modified

You can do this by excluding the HTML template files from the watchTransitiveSources task of your project, e.g. by adding this definition into your main Project definition:

watchTransitiveSources <<= watchTransitiveSources map { (sources: Seq[java.io.File]) =>
  sources
    .filterNot(source => source.isFile && source.getPath.contains("app/views") && !source.getName.endsWith(".scala.html") && source.getName.endsWith(".html"))
    .filterNot(source => source.isDirectory && source.getPath.contains("app/views"))
}

(this is planned to be done automatically by the SBT plugin in a future release)

Scala

In order to use the Groovy templates with Scala, mix in the eu.delving.templates.scala.GroovyTemplates trait. Then you can call templates like this:

 object Application extends Controller with GroovyTemplates {
 
   def fooAction = Action { implicit request =>
     Ok(Template('foo -> "bar"))
   }

}

This will render the /app/views/fooAction.html template, and pass the argument foo with the value bar.

Java

The Java API is less developed than the Scala one, but it is there nonetheless. In order to use it you need to extend the eu.delving.templates.java.GroovyTemplatesController. Then you can call templates like this:

public static Result index() {
  return ok(
    Template("index.html").params("foo", "bar", "foo2", 42).render()
  );
}

This will render the template /app/views/index.html and pass the parameters foo with the value bar and foo2 with the value 42.

Settings

The following settings (in application.conf or whever you application's configuration lives) influence the plugin's behaviour:

Changelog

1.6.2 - 26.08.2013

1.6.1 - 21.02.2013

1.6.0 - 20.02.2013

1.5.4 - 2.11.2012

1.5.3 - 24.10.2012

1.5.2 - 28.08.2012

1.5.1 - 08.08.2012

1.5 - 27.07.2012

1.4 - 4.07.2012

1.3 - 25.06.2012

1.2 - 4.06.2012

1.1 - 21.03.2012

1.0 - 13.03.2012