且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

小胡子{{{partial}}}与{{>部分的}}

更新时间:2023-12-01 08:03:40

语法{{> name}}用于部分,即包括另一个模板:

The syntax {{> name}} is for partials, i.e. to include another template:

车把允许通过局部使用模板.部分是 可以由其他人直接调用的普通把手模板 模板.

Handlebars allows for template reuse through partials. Partials are normal Handlebars templates that may be called directly by other templates.

{{{name}}}用于包含数据但不转义.如果您希望转义数据,请使用{{name}}:

whereas {{{name}}} is for including data without escaping it. If you wanted the data to be escaped, you'd use {{name}}:

Handlebars {{expression}}返回的HTML转义值.如果你 不想让把手逃脱一个值,请使用三重隐藏" {{{.

Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{.

所以它们是不同的东西.

So they are different things.

{{{body}}}指的是应用程序提供的当前上下文中的body属性(或者,它可以指代辅助函数,但实际情况并非如此).

{{{body}}} refers to a body property in the current context provided by your application (alternatively it could refer to a helper function but that's not the case here).

如果代码中包含{{>body}},则意味着您要加载一个名为body的模板.

If you had {{>body}} in the code, it would mean you have a template named body that you want handlebars to load.

请注意,如果您正确使用了Handlebars,则需要通过调用Handlebars.registerPartial来注册所有部分(如果您的项目使用express-handlebars,则它会为您完成所有操作,因此您不会在代码中找到它).

Note that, if you use Handlebars proper, all partials need to be registered by calling Handlebars.registerPartial (if your project uses express-handlebars, it does it all for you so you won't find this in the code).

Handlebars的文档可在 handlebarsjs.com 中找到.

Handlebars's documentation can be found at handlebarsjs.com.