Skip to content

Instantly share code, notes, and snippets.

@elgervb
Last active February 4, 2019 16:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elgervb/5c38c8d70870f92ef6338a291edf88e9 to your computer and use it in GitHub Desktop.
Save elgervb/5c38c8d70870f92ef6338a291edf88e9 to your computer and use it in GitHub Desktop.
Handlebars debug helper
/**
* 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