Class Template

java.lang.Object
com.samskivert.mustache.Template

public class Template extends Object
Represents a compiled template. Templates are executed with a context to generate output. The context can be any tree of objects. Variables are resolved against the context. Given a name foo, the following mechanisms are supported for resolving its value (and are sought in this order):
  • If the variable has the special name this the context object itself will be returned. This is useful when iterating over lists.
  • If the object is a Map, Map.get(java.lang.Object) will be called with the string foo as the key.
  • A method named foo in the supplied object (with non-void return value).
  • A method named getFoo in the supplied object (with non-void return value).
  • A field named foo in the supplied object.

The field type, method return type, or map value type should correspond to the desired behavior if the resolved name corresponds to a section. Boolean is used for showing or hiding sections without binding a sub-context. Arrays, Iterator and Iterable implementations are used for sections that repeat, with the context bound to the elements of the array, iterator or iterable. Lambdas are current unsupported, though they would be easy enough to add if desire exists. See the Mustache documentation for more details on section behavior.