2013-03-14 52 views
0

我正在使用鬍子,並且我有一個由不同HTML文件使用的模板。如何在單獨的文件中分離模板?

<script id="template" type="text/template"> 
{{#repo}} 
    <b>{{name}}</b> 
{{/repo}} 
</script> 

我想這個模板在一個單獨的文件隔離,如:

<script id="template" type="text/template" src="./js/template-must"></script> 

但是,這是行不通的。有任何想法嗎?

+0

如果你使用的是RequireJS,你可以試試[text插件](https://github.com/requirejs/text) – explunit 2013-03-14 19:58:50

回答

0
  1. 您可以使用後端將模板內容嵌入到script[type="text/template"]中。您可以像許多人一樣將模板文件保存在.mustache文件中。

    在你的HTML:

    enter image description here

  2. 即可將文字的RequireJS

  3. 您可以AJAX模板內容插件。
+0

明確的答案,非常感謝! – Laila 2013-03-14 21:48:08

相關問題