在模板中显示Handlebars.js上下文

问题描述:

是否在每个handlebar.js模板中传递了一个变量,该变量包含该模板可访问的所有上下文内容?

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

例如我正在创建一个模板,但是我不知道该模板可访问的所有上下文内容.我希望能够输入模板{{ debug }},handlebars.js会将所有上下文内容吐到HTML

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

您可以使用以下代码遍历this对象:

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

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

或通过@root对象迭代的类似代码:

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

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