Skip to content

Instantly share code, notes, and snippets.

@jnv
Forked from karlwestin/gist:3487951
Created September 8, 2017 09:46
Show Gist options
  • Save jnv/7fbcd91e1ec0b525c56312e18ac9f4b5 to your computer and use it in GitHub Desktop.
Save jnv/7fbcd91e1ec0b525c56312e18ac9f4b5 to your computer and use it in GitHub Desktop.
Handlebars logging - tips for debugging templates!
/*
* Use this to turn on logging: (in your local extensions file)
*/
Handlebars.logger.log = function(level) {
if(level >= Handlebars.logger.level) {
console.log.apply(console, [].concat(["Handlebars: "], _.toArray(arguments)));
}
};
// DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3,
Handlebars.registerHelper('log', Handlebars.logger.log);
// Std level is 3, when set to 0, handlebars will log all compilation results
Handlebars.logger.level = 3;
/*
* Log can also be used in templates: '{{log 0 this "myString" accountName}}'
* Logs all the passed data when logger.level = 0
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment