在外部文件中创建把手模板

时间:2014-10-27 16:01:33

标签: handlebars.js

我的问题很简单,虽然我找不到办法。

我基本上想把所有把手模板都放在外面。 这是我的示例模板文件。它被称为example.js

<script id="test_template">
<div>Hello world!</div>
</script>

当我将其包含在html文件中时,我收到以下错误:

Uncaught SyntaxError: Unexpected token < 

对于第一行 - 浏览器并不高兴javascript源文件中有一些html。

我的问题是:它的方式是什么?将模板拆分成手柄中的文件的标准方法是什么?

1 个答案:

答案 0 :(得分:0)

在文件中添加type="text/x-handlebars-template"

<script type="text/x-handlebars-template" id="test_template">
    <div>Hello world!</div>
</script>

对于外部文件,请查看: https://github.com/wycats/handlebars.js/issues/82