繁体   English   中英

使用自定义帮助器预编译车把模板

[英]Precompiling handlebars template with custom helpers

我有一个message.handlebars模板,在浏览器中进行编译时可以完美工作。

我成功地使用handlebars -message.handlebars -f -message.js对其进行了预编译。

然后在我的ASP.NET MVC网站中,将引用添加为:

<script src="~/Scripts/handlebars.runtime-v1.3.0.js"></script>
<script src="~/Scripts/handlebars-helpers.js"></script>
<script src="~/Scripts/templates/message.js"></script>

handlebars-helpers.js包含消息模板使用的一些自定义帮助器。

我从这个人的评论中采用了这种方法,但是它没有用。 在执行var html = Handlebars.templates.message(data);时出现错误var html = Handlebars.templates.message(data); 同样,在浏览器中进行编译时,这非常完美,因此这不是上下文的问题。

我得到的错误是: 在此处输入图片说明

这是预编译和使用自定义助手的正确方法吗? 还是有办法在预编译的模板中包含这些助手?

它是服务器上把手的版本。 NPM默认情况下安装最新版本,而版本2 Alpha导致了该问题。 在Github( https://github.com/wycats/handlebars.js/issues/734 )上找到此修复程序:

npm uninstall handlebars -g
npm install handlebars@1.3 -g

一切正常!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM