handlebars-helper-maybe
v1.0.0
Published
Handlebars helpers for rendering optional values
Downloads
2
Readme
handlebars-helper-maybe
Handlebars helpers for rendering optional values.
Installation
Install using npm:
$ npm install handlebars-helper-maybe
Usage
var Handlebars = require('handlebars');
var MaybeHelpers = require('handlebars-helper-maybe');
Handlebars.registerHelper('isJust', MaybeHelper.isJust);
Handlebars.registerHelper('maybe', MaybeHelper.maybe);
Helpers
{{#isJust}}
Block helper that renders the block if the given value is a Just
. If an
inverse block is specified, it will be rendered if the value is a Nothing
.
Example
{{#isJust value}}
Just {{this}}
{{else}}
Nothing
{{/isJust}}
{{maybe}}
Returns the value inside the Maybe. If the argument is a Nothing
and the
defaultValue
option is specified, this will return the provided default
value. Otherwise it will return undefined
.
Example
{{maybe value defaultValue="Not Available"}}
Related
What's a Maybe?
Known Supported Maybe Implementations
License
MIT