【问题标题】:how to include handlebars templates that are also used in express如何包含也用于 express 的车把模板
【发布时间】:2014-11-20 15:44:43
【问题描述】:

我有一个使用把手作为视图模板引擎的快速应用程序。

我有一个页面被编写为车把模板。问题是该页面的一部分必须由服务器渲染,而其他部分必须在客户端渲染。

<body>
    <div>my page with handlebars {{me}}</div>
    <script id="each-template" type="text/x-handlebars-template" src="/partials/model1.js">
        sample template {{friend}}
    </script>
</body>

问题是页面完全呈现给客户端(包括 中的模板)。

<body>
    <div>my page with handlebars Patricio</div>
    <script id="each-template" type="text/x-handlebars-template" src="/partials/model1.js">
        sample template 
    </script>
</body>

但应该是:

<body>
<div>my page with handlebars Patricio</div>
<script id="each-template" type="text/x-handlebars-template" src="/partials/model1.js">
    sample template {{friend}}
</script>

如何得到这个结果?

【问题讨论】:

标签: node.js express handlebars.js


【解决方案1】:

完成这项工作的最快和最好的方法是使用预编译的车把模板:

http://handlebarsjs.com/precompilation.html

然后消费然后使用运行时

http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars.runtime-v2.0.0.js

这样,没有要扫描的标记,客户端和服务器都可以使用相同的预编译模板

【讨论】:

    猜你喜欢
    • 2015-08-08
    • 2013-07-16
    • 1970-01-01
    • 2014-01-06
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 2019-07-27
    相关资源
    最近更新 更多