# @data 变量

¥@data variables

以下 @data 变量由 Handlebars 及其内置助手实现。

¥The following @data variables are implemented by Handlebars and its builtin helpers.

# @root

执行模板所使用的初始上下文。

¥Initial context with which the template was executed.

{{#each array}} {{@root.foo}} {{/each}}

除非显式修改,否则该值在页面渲染的所有部分中都是一致的,这意味着它可以在深度参数无法引用其父模板的部分中使用。

¥Unless explicitly modified, this value is consistent across all portions of the page rendering, meaning it can be used within partials where depthed parameters are unable to reference their parent templates.

# @first

对于迭代的第一步,由 each 辅助程序设置为 true。

¥Set to true by the each helper for the first step of iteration.

{{#each array}} {{#if @first}} First! {{/if}} {{/each}}

# @index

当前迭代步骤的从零开始的索引。由 each 助手设置。

¥Zero-based index for the current iteration step. Set by the each helper.

{{#each array}} {{@index}} {{/each}}

# @key

当前迭代步骤的键名。迭代对象时由 each 助手设置。

¥Key name for the current iteration step. Set by the each helper when iterating over objects.

{{#each array}} {{@key}} {{/each}}

# @last

对于迭代的最后一步,由 each 助手设置为 true。

¥Set to true by the each helper for the last step of iteration.

{{#each array}} {{#if @last}} Last :( {{/if}} {{/each}}

# @level

指定的日志级别。

¥Assigned log level.

template({}, { data: { level: Handlebars.logger.WARN } });

可以设置为 Handlebars.logger.DEBUGHandlebars.logger.INFOHandlebars.logger.WARNHandlebars.logger.ERROR 之一

¥May be set to one of Handlebars.logger.DEBUG , Handlebars.logger.INFO , Handlebars.logger.WARN , or Handlebars.logger.ERROR

设置后,日志器将仅在其输出中包含日志级别为 Handlebars.logger.level 或更高的消息。默认值为 Handlebars.logger.ERROR

¥When set, the logger will include in its output only messages with a log level of Handlebars.logger.level or higher. The default value is Handlebars.logger.ERROR.

Last Updated: 2024/4/16 21:37:19