ToString Mode
This is NOT a Play specific feature.
Rythm (starts from v1.0.0-20120704) provides an new feature called TSM, the “To String Mode”.
public class Address {
public String unitNo;
public String streetNo;
public String street;
public String suburb;
public String state;
public String postCode;
// use Rythm.toString() API call
@Override public String toString() {
return Rythm.toString("@_.unitNo @_.streetNo @_.street, @_.suburb, @_.state, @_.postCode", this);
}
}
Without TSM you will need to declare the type in the template:
return Rythm.render("@args Address _;@_.unitNo @_.streetNo @_.street, @_.suburb, @_.state, @_.postCode", this);
To specify Rythm to render with TSM, use Rythm.toString(...) API instead of Rythm.render(...) API.
Rythm.toString() API
Rythm.toString() API accept 2 parameters:
- the template spec, could be either template content, or template file/resource name
- an object, usually it’s specified by
thiskeyword
All expressions used inside TSM template starts with _. where “_” means this object.