Skip to content

Instantly share code, notes, and snippets.

@adeubank
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeubank/a8df5ba181ff3126e381 to your computer and use it in GitHub Desktop.
Save adeubank/a8df5ba181ff3126e381 to your computer and use it in GitHub Desktop.
Have handlebars output a JSON object of 'this' or passed in value. In my Googling, I didn't find anything on my first try, so I made this!
Handlebars.registerHelper('inspect', function(context) {
return JSON.stringify(context, null, 2) || JSON.stringify(this, null, 2);
});
// Usage: <pre>{{inspect}}</pre> or <pre>{{inspect variableName}}</pre> for nicely formatted code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment