I am having an issue with the HandlebarsHelper compiled templates on an MVC5 site. Here is the code for the BundleConfig:
bundles.Add(new Bundle("~/bundles/templates", new HandlebarsTransformer())
.IncludeDirectory("~/App/templates", "*.hbs", true));
This was working fine locally and then I pushed to a server hosting the QA environment and I was getting an assembly reference error saying the HandlebarsHelper plugin was calling Jurassic 2.1.0.0 and it wasn't found. So I added Jurassic through Nuget, since then the templates stopped working. I get this error from the browser:
Chrome:
Uncaught TypeError: undefined is not a function
Firefox:
TypeError: templateSpec.call is not a function
This is happening in the following section of handlebars.js:
return function(context, options) {
options = options || {};
var namespace = options.partial ? options : env,
helpers,
partials;
if (!options.partial) {
helpers = options.helpers;
partials = options.partials;
}
var result = templateSpec.call(
container,
namespace, context,
helpers,
partials,
options.data);
if (!options.partial) {
env.VM.checkRevision(container.compilerInfo);
}
return result;
};
I am running:
Ember 1.7.0
Ember-Data 1.0.0-beta.11
Handlebars 1.3.0
JQuery 2.1.1
MVC 5
.Net 4.5.2
I have been searching online all morning and not found any answers yet that have worked, I tried removing the Jurassic Nuget package and it did not help. Any ideas would be appreciated, let me know if there is any other info that would help diagnosing the issue.
You're on a version of HandlbarsHelper that's not supported for that version of Ember.js.
There was a breaking change for version 1.9 which added support for handlebars version 2.0. This is supported in HandlebarsHelper v2.0+. As a breaking change it means 2.0+ can't be used with Ember.JS < v1.9 and Handlebars < v2.0.
The reason why it was probably working initially was because in debug templates are usually just injected into the page unminified.
Easy fix is to use HandlebarsHelper v1.1 (https://www.nuget.org/packages/HandlebarsHelper/1.1.0)
The problem was I was using a version of Handlebars Helper that only supported handlebars 2.x. Found the issue in Nuget and changed it to a different version, everything works now. Thanks for the comments.
Related
In our application we use the template compiler at runtime by calling Ember.HTMLBars.compile with a handlebars template. Example code:
let myTemplate = `{{foo}}`;
application.register(`template:my-template`, Ember.HTMLBars.compile(myTemplate));
I've tried to upgrade from Ember 2.6 to Ember 2.7 but I get the following error in the developer console if I try to compile the template:
_ember.default.HTMLBars.compile is not a function()
In the documentation I couldn't find anything about the compile method being removed from the HTMLBars compiler.
How can I still use/enable the HTMLBars compiler at runtime in my application?
import original ember-template-compiler.js in ember-cli-build.js
app.import('bower_components/ember/ember-template-compiler.js');
I was needed to compile template during runtime
und used https://www.npmjs.com/package/ember-cli-handlebars-inline-precompile.
Try this:
import hbs from 'htmlbars-inline-precompile';
application.register(`template:my-template`, hbs`{{foo}}`);
Since there is less information provided, first try and check the error source.
presumably a library it is, you need to open your developers console [lets say chrome] and then click on the error which will direct you to where the error originates from so you can adjust or rectify the code...
The Readme for Ember-hash-helper-polyfill says that it can be used in ember versions 1.13 -> 2.2. Does this mean it can not be used in older versions(such as 1.11)?
I have checked this out. Looks like it works for version 1.11 as well.
Initially, I was getting an error because the consuming addon was yielding a closure action in the hash.
I've upgraded my ember version to 1.9.1 and handlebar version to 2.0.0. But now getting the error "Unknown template object: function" in app. The app worked perfectly with ember 1.8.1 and handlebars 1.3.0.
As I suspected, you're not using the correct template compiler for your version of Ember. The grunt-ember-templates readme has instructions on this, but the gist is that you need to point it to the correct template compiler like this:
options: {
templateCompilerPath: 'bower_components/ember/ember-template-compiler.js',
handlebarsPath: 'bower_components/handlebars/handlebars.js',
templateNamespace: 'HTMLBars'
}
You can also look at this pull request for more details.
I try to update https://github.com/trek/ember-todos-with-build-tools-tests-and-other-modern-conveniences
with the newest versions of some scripts. All work except Ember (1.2.0) gives an error:
Assertion failed: Ember Handlebars requires Handlebars version 1.0 or 1.1. Include a SCRIPT tag in the HTML HEAD linking to the Handlebars file before you link to Ember.
Error disappears when I activate the same script without dependencies but with
<script src="../dependencies/handlebars.js"></script>
I think question should be marked as answered. I got it work with https://github.com/gcollazo/brunch-with-ember-reloaded
I'm using the ember-rails gem and following along with the starter screencast on the Emberjs.com site. When I create this link
<li>{{#link-to 'about'}} About {{/link-to}}</li>
It's giving me this error
Uncaught Error: Handlebars error: Could not find property 'link-to' on object <(generated application controller):ember280>.
There's a StackOverflow question that deals with this issue Helpers not properly defined in application template?. One answer says that
When you use Handlebars.compile it uses the handlebars script instead
of the Ember script. Ember has its own handlebars object that extends
the original Handlebars object with extra templates.
and gives this example
Ember.TEMPLATES["application"] = Ember.Handlebars.compile("{{#linkTo 'dashboard'}}Dashboard{{/linkTo}}")
However, I'm unclear where to put that code, and would it need to be done for every link?
I suspect you're running an older version of ember. Try running this to get the latest version of Ember into your app.
rails generate ember:install --head