Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A snippets helper for debugging handlebars. Appends debug to all templates so you don't have to type it in yourself, and when a template is rendered, the context is logged in the console.
var scriptsNodeList = document.getElementsByTagName('script'),
debugSet = false,
templates, scripts;
// convert node list to array
scripts =;
templates = scripts.filter(function(script) {
return script.type === 'text/x-handlebars-template';
}).forEach(function(template) {
if (debugSet) return;
var debug = document.createTextNode('{{debug}}');
debugSet = true;
Use: In templates add {{debug}}
Handlebars.registerHelper("debug", function(optionalValue) {
console.log("Current Context");
for(var key in this) {
console.log('%c' + key + ': ', 'background-color: #00CDAC; color: #fff; padding: 3px;')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment