feature: strict rendering, close #9

This commit is contained in:
harttle
2016-09-26 23:25:08 +08:00
parent be6c67a1ba
commit 937d213a2d
8 changed files with 101 additions and 68 deletions
+20
View File
@@ -58,6 +58,26 @@ engine.renderFile("hello", {name: 'alice'})
`cache` default to `false`, `extname` default to `.liquid`, `root` default to `""`.
## Strict Rendering
Undefined filters and variables will be rendered as empty string by default.
Enable strict rendering to throw errors upon undefined variables/filters:
```javascript
var opts = {
strict_variables: true,
strict_filters: true
};
engine.parseAndRender("{{ foo }}", {}, opts).catch(function(err){
// err.message === undefined variable: foo
});
engine.parseAndRender("{{ 'foo' | filter1 }}", {}, opts).catch(function(err){
// err.message === undefined filter: filter1
});
// Note:
// `engine.render(tpl, ctx, opts)` and `engine.renderFile(path, ctx, opts)` also works.
```
## Use with Express.js
```javascript