Last active
February 4, 2019 16:55
-
-
Save elgervb/5c38c8d70870f92ef6338a291edf88e9 to your computer and use it in GitHub Desktop.
Handlebars 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
/** | |
* Register a debug helper for Handlebars to be able to log data or inspect data in the browser console | |
* | |
* Usage: | |
* {{debug someObj.data}} => logs someObj.data to the console | |
* {{debug someObj.data true}} => logs someObj.data to the console and stops at a debugger point | |
* | |
* https://gist.github.com/elgervb/5c38c8d70870f92ef6338a291edf88e9 | |
* | |
* @param {any} the data to log to console | |
* @param {boolean} whether or not to set a breakpoint to inspect current state in debugger | |
*/ | |
Handlebars.registerHelper( 'debug', function( data, breakpoint ) { | |
console.log(data); | |
if (breakpoint === true) { | |
debugger; | |
} | |
return ''; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment