我正在使用Handlebars.js,目前我的所有模板都存在于脚本标签中,这些脚本标签内部包含数十个其他模板的.html文件,也位于脚本标签内。如何将客户端模板组织成单个文件?
<script type="text/template" id="template-1">
<div>{{variable}}</div>
</script>
<script type="text/template" id="template-2">
<div>{{variable}}</div>
</script>
<script type="text/template" id="template-3">
<div>{{variable}}</div>
</script>
...
然后我把这个文件作为一个部分包含在服务器端。
这有以下缺点:
- 模板一堆被塞进HTML文件。
- 找到给定的模板是很乏味的。
我正在寻找更好的方式来组织我的模板。我希望每个模板都能在自己的文件中生存。例如:
/public/views/my_controller/my_action/some_template.html
/public/views/my_controller/my_action/some_other_template.html
/public/views/my_controller/my_other_action/another_template.html
/public/views/my_controller/my_other_action/yet_another_template.html
/public/views/shared/my_shared_template.html
在我看来顶部
然后,在后端代码,我可以将这些模板页面加载时,像这样:
SomeTemplateLibrary.require(
"/public/views/my_controller/my_action/*",
"/public/views/shared/my_shared_template.html"
)
这将包括所有模板/ public/views/my_controller/my_action /还包含/public/views/shared/my_shared_template.html。
我的问题:有没有提供这种或类似功能的库?或者,有没有人有其他组织建议?
看起来这个链接是坏的:( – iX3