Added compiler option to provide defaults for missing values

Call missingVariableValue(value) on a Compiler object to get a new
version that will insert "value" for missing values (rather than
throwing an exception).  Useful when you have templates you would
rather generated *something* instead of erroring or for when objects may
have null values themselves.
This commit is contained in:
John Montgomery
2011-04-15 10:01:40 +01:00
parent d04f2c2f76
commit 5d59eada29
3 changed files with 44 additions and 7 deletions
@@ -126,6 +126,12 @@ public class Template
return null;
}
protected Object getValueWithDefault (Context ctx, String name, int line)
{
Object value = getValue(ctx, name, line);
return value != null? value : _compiler.missingVariableValue;
}
protected Object getValueIn (Object data, String name, int line)
{
if (data == null) {