Community contributed extensions

Integration Guide

Migrate your current project from Groovy template engine to Rythm

PlayRythm is designed to support smooth migrating from Groovy template engine.

By default “system” (i.e. groovy) template engine is used. Meaning without special annotation, controller’s render request will be handled by groovy template engine. And this give developer a good base to move to Rythm template step by step.

  1. Step 1, rewrite a groovy template using rythm syntax and put the file into the corresponding place in app/rythm
  2. Step 2, annotate the relevant controller action method with @UseRythmTemplateEngine annotation

Continue the above steps until all your controller migrated to rythm. You can annotate the controller with @UseRythmTemplateEngine and drop all that from action method

Tip: enclose all your rythm template with #{verbatim} and #{/verbatim} can help you avoid groovy compile exception and does not impact your rythm template. This is not true. The groovy template engine will still parse the expressions. See Resolve groovy compilation error for workarounds.

Resolve groovy compilation error

Because groovy template engine does not provide a way to skip parsing any part of the template file, the rythm template file might cause compilation error during precompile process, where rythm has no way to identify some files been a rythm template or groovy template, e.g. some json generation template. Start from version 0.9.5 it’s suggest to move all rythm templates or at least those compilation error causing templates to app/rythm folder from app/views folder.

More about tags

So far you can keep rythm tags file under app/views/tags/ryth folder. However it is recommened not to use tags folder at all since every rythm template is a tag and can be called from any other rythm templates. E.g. suppose you have a template file app/views/Order/list.html, while you can use it as an ordinary template file, you also free to call it as a tag from other rythm template like: @Order.list(myOrders)

Invoking controller actions

PlayRythm 0.9.7 version released with this new feature which is first introduced in Japid template engine and people seems like it a lot. Basically you can invoke a controller action method directly from within the template and fill the place with the render result content. As with any function/tag/template invocation, action method invoke is very straghtforward. Excamples:

@controllers.Applicaiton.index();
@controllers.MyPortal.newsPanel(user);

Things you need to take care of:

  1. You must use full qualified method name (including package name, class name) when you invoke controller action method
  2. You must pass exactly the parameters that matches what is defined in the controller action method signature
  3. The invocation is directly and will not go through the whole stack of Play’s method action invocation. Meaning the @Before, @After and @Final logic will NOT be executed.
  4. Cache is not supported so far but will come out soon

See Also

  1. Rythm Template User guide
  2. Reference manual