From 66ba7c8cf819964996d36cce2e9ace8f4ac76760 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 29 Oct 2011 13:14:02 -0700 Subject: [PATCH] Added additional information about compound keys and null/default values. --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f3658f..3770f58 100644 --- a/README.md +++ b/README.md @@ -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 ----------------