原諒noob問題,但我根本無法預編譯把手模板做任何事情,但我每個應用上下文的(預編譯)模板的時間BARF出類型錯誤將預編譯的把手模板與上下文
TypeError: 'undefined' is not a function (evaluating 'templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data)')
。
鑑於下列文件和內容:
- hello.handlebars:
<p>Hello, {{name}}</p>
- templates.js:通過
handlebars hello.handlebars -f templates.js
指數編制hello.handlebars的結果.html:包括Handlebars RC1 runtime在
head
,這對於身體:<body id="body"> <script src="templates.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript" charset="utf-8"> var compiledTemplate = Handlebars.templates['hello']; var html = compiledTemplate({ name: 'World' }); document.getElementById('body').innerHTML = html; </script> </body>
調用compiledTemplate()
拋出錯誤上面不管我做什麼 - 但我能夠獲得客戶端模板編譯並顯示就好了。我所見過的所有演練和教程都略過了這個,所以我必須錯過一些愚蠢的東西。有任何想法嗎?
這幫了我。 npm默認安裝'handlebars-2.0.0-alpha' ...這與運行時不兼容1.3.0 – otmezger
我正在運行[1.0.rc.1](https://github.com/wycats/handlebars .js/downloads)。 – ele
@ele,我建議你 - 如果可能的話 - 升級到Handlebars的更新版本,因爲1.0.rc.1的日期從2012年9月開始。最新的穩定版本從2014年1月起是1.3.0,因此可能會有很多改進你也會失蹤。 您可以從[Handlebars Home](http://handlebarsjs.com/)下載最新的穩定客戶端(即運行時js模塊)。 節點編譯器(服務器模塊)可以從npm下載(指定版本,以防止下載一些新的alpha版本),或從[Github發佈網站](https://github.com/wycats/handlebars.js /釋放)。 – biomorgoth