From 31d0a0985d78daea584788f3e8e14fd6666dc889 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 15 Apr 2011 12:45:54 -0700 Subject: [PATCH] Added usage for default values. --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index f524f54..5050fe6 100644 --- a/README.md +++ b/README.md @@ -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 ==========