Display context of Handlebars.js in template

Is there a variable passed into each handlebar.js template that contains all the contextual content available to the template?

eg. I am creating a template, but I do not know all the contextual content available to the template. I want to be able to enter {{ debug }} into the template, and handlebars.js spits out all the contextual content in HTML

+4
source share
3 answers

Handles have a built-in auxiliary log .

You just need to set the logging level to DEBUG .

 Handlebars.logger.level = 0; 

Then use the helper:

 {{log this}} 

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

+3
source

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

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

or a similar piece of code repeating through the @root object:

 {{#each @root}} {{@key}}: {{this}} {{/each}} 
+3
source

Although this question is somewhat old, someone might find this useful. You can simply flush the current descriptor context into plain text with

 {{{.}}} 
0
source

All Articles