[英]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.