Last active
August 29, 2015 14:19
-
-
Save carltondickson/ddae15ce1bab5410695c to your computer and use it in GitHub Desktop.
Handlebarjs debug helper
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
Handlebars.registerHelper("debug", function(optionalValue) { | |
console.log("Current Context"); | |
console.log("===================="); | |
console.log(this); | |
if (optionalValue) { | |
console.log("Value"); | |
console.log("===================="); | |
console.log(optionalValue); | |
} | |
}); | |
/* | |
You could then use that helper in any template like: | |
{{debug}} | |
{{debug someValue}} | |
Current Context | |
==================== | |
email: "alan@test.com" | |
first_name: "Alan" | |
last_name: "Johnson" | |
member_since: "Mar 25, 2011" | |
phone: "1234567890" | |
stripeClass: "even" | |
__proto__: Object | |
Value | |
==================== | |
Alan | |
*/ | |
// source http://blog.teamtreehouse.com/handlebars-js-part-3-tips-and-tricks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment