Created
May 21, 2012 15:32
-
-
Save asselin/2762936 to your computer and use it in GitHub Desktop.
Handlebars helper for generic Javascript expressions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This helper allows you to use generic javascript expressions in a handlebars template. It can be used to call Javascript functions on a value or do data structure access that Handlebars doesn't support (e.g. accessing an element of an array). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <input type="text" data-dojo-type="dijit.form.TextBox" value='{{jsexpr "val[1]"}}'/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Handlebars.registerHelper('jsexpr', function(expr) { | |
| if (arguments.length < 2) | |
| throw new Error("Handlerbars Helper 'arrayaccess' needs 1 parameter"); | |
| with (this) {return eval(expr)}; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment