8

Is there a variable passed into every handlebar.js template that contains all the context content that is accessible by the template?

e.g. I'm creating a template, but I don't know all the context content accessible by the template. I want to be able to type into the template {{ debug }} and handlebars.js will spit out all the context content into the HTML

Tri Noensie
  • 786
  • 7
  • 24

3 Answers3

7

You can use the following code to iterate through this object:

{{#each this}}
  {{@key}}: {{this}}
{{/each}}

or a similar piece of code iterating through @root object:

{{#each @root}}
  {{@key}}: {{this}}
{{/each}}
CaptainRR
  • 421
  • 5
  • 17
4

Handlebars has built-in helper log.

You just need to set logging level to DEBUG.

Handlebars.logger.level = 0;

Then use helper:

{{log this}}

EDIT: Sorry, this will not write context to HTML, helper uses console.log. For outputting to HTML you need to write custom helper that will use for example JSON.stringify.

raidendev
  • 2,729
  • 1
  • 22
  • 23
0

Though this question is somewhat old, someone might find this usefull. You can just dump the handlebars current context into plain text with;

{{{.}}}
Govinnage Rasika Perera
  • 2,134
  • 1
  • 21
  • 33