Last active
August 29, 2015 14:05
-
-
Save gwendall/83ca0263d5d9dd72d490 to your computer and use it in GitHub Desktop.
Helper that brings Underscore directly in Meteor Templates
This file contains 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
UI.registerHelper('_', function() { | |
arguments = _.toArray(arguments); | |
var self = this, | |
fn = arguments[0]; | |
arguments.shift(); // Removes the Underscore function | |
arguments.pop(); // Remove the Spacebars appended argument | |
return _[fn].apply(self, arguments); | |
}); | |
/* | |
Example: | |
{{#if _ "isString" "bonjour"}} | |
It is! | |
{{else}} | |
It is not :( | |
{{/if}} | |
Would return "It is!" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mind blown! Thanks.