在html中包含.handlebars或.hbs文件

时间:2022-09-09 21:11:05

At the homepage of emberjs.com there is a emberjs & handlebarsjs example of a todo list. On the todo list there is a extension for a .hbs file and I was wondering what is .hbs? And how do I include a .hbs script to HTML? Something like this:

在emberjs.com的主页上有一个emberjs&handlebarsjs todo列表的例子。在todo列表上有一个.hbs文件的扩展名,我想知道什么是.hbs?我如何在HTML中包含.hbs脚本?像这样的东西:

<script type="text/hbs" src="hbs-file.hbs"></script>

1 个解决方案

#1


20  

It's a handlebars template file which is a piece of HTML with handlebars tokens in it. It doesn't matter what the file extension is; it can be anything you want.

这是一个把手模板文件,它是一个带有把手令牌的HTML。文件扩展名是什么并不重要;它可以是你想要的任何东西。

To include a handlebars template in your own HTML, you just create the file, give it any name you like, and then include a <script> tag like the one in the example that points to your template file.

要在自己的HTML中包含把手模板,只需创建文件,为其指定任何名称,然后包含

One way of using client-side handlebars templates is to include them in script tags (as in your example). The raw template will be available in the DOM, but not made visible and not processed as HTML so it it already available to your code so it can be compiled into a template by your client javascript and then rendered to HTML with a specific set of data.

使用客户端把手模板的一种方法是将它们包含在脚本标记中(如示例中所示)。原始模板将在DOM中可用,但不可见并且不作为HTML处理,因此它已经可用于您的代码,因此可以通过客户端javascript将其编译为模板,然后使用一组特定数据将其呈现为HTML 。

Handlebars templates can also be in your javascript, built by your javascript, or can be loaded dynamically via Ajax (two other ways of getting them into the client in addition to the <script> tag method).

Handlebars模板也可以在您的javascript中,由您的javascript构建,或者可以通过Ajax动态加载(除了

If you were using handlebars server-side, then the templates can stay on the server and don't need to be put in the page as <script> tags.

如果您使用服务器端的把手,那么模板可以保留在服务器上,而不需要作为

#1


20  

It's a handlebars template file which is a piece of HTML with handlebars tokens in it. It doesn't matter what the file extension is; it can be anything you want.

这是一个把手模板文件,它是一个带有把手令牌的HTML。文件扩展名是什么并不重要;它可以是你想要的任何东西。

To include a handlebars template in your own HTML, you just create the file, give it any name you like, and then include a <script> tag like the one in the example that points to your template file.

要在自己的HTML中包含把手模板,只需创建文件,为其指定任何名称,然后包含

One way of using client-side handlebars templates is to include them in script tags (as in your example). The raw template will be available in the DOM, but not made visible and not processed as HTML so it it already available to your code so it can be compiled into a template by your client javascript and then rendered to HTML with a specific set of data.

使用客户端把手模板的一种方法是将它们包含在脚本标记中(如示例中所示)。原始模板将在DOM中可用,但不可见并且不作为HTML处理,因此它已经可用于您的代码,因此可以通过客户端javascript将其编译为模板,然后使用一组特定数据将其呈现为HTML 。

Handlebars templates can also be in your javascript, built by your javascript, or can be loaded dynamically via Ajax (two other ways of getting them into the client in addition to the <script> tag method).

Handlebars模板也可以在您的javascript中,由您的javascript构建,或者可以通过Ajax动态加载(除了

If you were using handlebars server-side, then the templates can stay on the server and don't need to be put in the page as <script> tags.

如果您使用服务器端的把手,那么模板可以保留在服务器上,而不需要作为