Reputation: 11788
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:
Is this the correct approach to precompile and use custom helpers? Or is there a way to include those helpers in the precompiled template?
Upvotes: 3
Views: 1967
Reputation: 11788
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 [email protected] -g
Everything working!
Upvotes: 1