Added additional information about compound keys and null/default values.

This commit is contained in:
Michael Bayne
2011-10-29 13:14:02 -07:00
parent 0a27e6ce4d
commit 66ba7c8cf8
+21 -1
View File
@@ -270,9 +270,29 @@ example:
By taking advantage of reflection and bean-property-style lookups, you can do kooky things:
Mustache.compiler().compile("Hello {{this.class.name}}!").execute(new Object());
Mustache.compiler().compile("Hello {{class.name}}!").execute(new Object());
// result: Hello java.lang.Object!
Note that compound variables are essentially short-hand for using singleton
sections. The above examples could also be represented as:
"Hello {{#field}}{{who}}{{/field}}"
"Hello {{#class}}{{name}}{{/class}}"
Note also that one semantic difference exists between nested singleton sections
and compound variables: compound variables do not make use of the default value
and null value configuration. If a null or missing value is encountered while
resolving a compound section, an exception is always raised.
If you desire for a default value to be used when null or missing values are
encountered, use the somewhat more verbose singleton sections. The use of
sections clearly communicates to someone reading the template that the section
will not be rendered if the object it references is missing or null and allows
for a site-specific default value to be used, as in:
{{#foo}}{{name}}{{/foo}}
{{^foo}}Missing foo!{{/foo}}
Newline trimming
----------------