Added usage for default values.

This commit is contained in:
Michael Bayne
2011-04-15 12:45:54 -07:00
parent 1be9c52589
commit 31d0a0985d
+16
View File
@@ -131,6 +131,22 @@ If you wish to make use of partials (e.g. `{{>subtmpl}}`) you must provide a
The above snippet will load `new File(templateDir, "subtmpl")` when compiling
the template.
Default Values
--------------
By default, an exception will be thrown any time a variable cannot be found, or
resolves to null. A value to use in such circumstances can be provided when
creating your compiler:
String tmpl = "{{exists}} {{nullValued}} {{doesNotExist}}?";
Mustache.compiler().defaultValue("what").compile(tmpl).execute(new Object() {
String exists = "Say";
String nullValued = null;
// String doesNotExist
});
// result:
Say what what?
Extensions
==========