سؤال

I have a message.handlebars template which works perfect when compiling it in the browser.

I precompiled it with handlebars -message.handlebars -f -message.js successfuly.

Then in my ASP.NET MVC site I'm adding the references as:

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

The handlebars-helpers.js contains some custom helpers used by the message template.

I took this approach from this guy's comment, but it's not working. I'm getting an error when doing var html = Handlebars.templates.message(data);. Again this works perfectly when compiling it in the browser, so it's not a problem of context.

The error I'm getting is: enter image description here

Is this the correct approach to precompile and use custom helpers? Or is there a way to include those helpers in the precompiled template?

هل كانت مفيدة؟

المحلول

It was the version of handlebars on the server. NPM installs the latest by default and the version 2 alpha was causing the issue. Found this fix on Github (https://github.com/wycats/handlebars.js/issues/734):

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

Everything working!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top