PlayRythm module documentation
Welcome to PlayRythm module documentation. This documentation is intended for the 0.9 beta release and may significantly differ from previous module version’s documentation.
Check the version history.
PlayRythm features
PlayRythm is yet another template engine plugin for Play!Framework 1.2x version:
- Static and strong typed pure Java template. Yes it’s like Japid and Jamon
- Razor like syntax
- Transparently integrated with Play!Framework. Just follow what you did with Groovy template is okay, no RythmController, no rythmview. Think PlayRythm as an unobtrusive Japid.
- Support layout and tag, as you did in Groovy template
- Support FastTags and JavaExtensions with constraints
Template Syntax at a glance
Based on Rythm template engine, PlayRythm module provides an easy to read/write template language which is very like that is used in .Net MVC’s Razor template engine. Here is one rythm template example:
@extends(/main.html);
@args List<User> users;
...
<ul>
@for(User user: users) {
@if (!user.disabled()) {
<li class="@user_parity">
<span>@user_index</span>
<a href="@_u(User.show(user.getId()))">user.getName()</a>
</li>
}
}
</ul>
Use PlayRythm template engine
1. Add PlayRythm into your dependencies.conf file:
# Application dependencies
require:
- play -> rythm
2. Process your controller action method:
@UseRythmTemplateEngine public static void list() {
List<User> users = User.findAll();
render(users);
}
So as you can see, you don’t need to rewrite your existing controller action methods, just annotate it with @UseRythmTemplateEngine is enough. PlayRythm will shortcut template loading process and process the template rendering before Play’s default groovy template engine activated.
You can also annotate @UseRythmTemplateEngine on Controller class declaration, which mark all action methods inside this controller to be processed by PlayRythm template engine.
If you set rythm.default.engine=rythm in your application.conf file, then you don’t need @UseRythmTemplateEngine annotation because all your templates will be processed by PlayRythm by default unless you have annotated UseSystemTemplateEngine to your controller class or action methods, which explicitly indicate the relevant rendering request shall not be processed by PlayRythm and leave it to Play’s built-in template engine.
3. Write your view or port your existing view using Rythm syntax.
This might be the hardest part but not that hard as almost all Groovy template’s keywords or facility has corresponding part provided by Rythm template engine. Please refer to Rythm Template User Guide for more information