Using the ember-rails rail handle template outside the ember view context

I have a rails application that uses ember-rails stone.

There is a section of my site that is not located on ember, but where it would be convenient to use one of the steering templates served by the asset pipeline. However, something seems wrong. In particular, my template is returned like this:

 Ember.TEMPLATES["views/wanderlists/templates/gallery"] = Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) { helpers = helpers || Ember.Handlebars.helpers; var self=this; data.buffer.push("<h1>Gallery!</h2>\n"); }); 

However, if I try to use this template:

 Ember.TEMPLATES["views/wanderlists/templates/gallery"]({}) TypeError: Cannot read property 'buffer' of undefined 

Any idea why the generated template will have problems?

+4
source share
1 answer

Any idea why the generated template will have problems?

You cannot call handlebars templates compiled by the ember handlebars compiler as if they were regular steering patterns. They expect a completely different set of arguments. In particular, they expect that they will be passed (context, options) , where the options have a data.buffer file to which the output will be written. For example, if you try:

 Ember.TEMPLATES["views/wanderlists/templates/gallery"](this, {data: {buffer: 'NOT-A-BUFFER'}}) 
Console

should TypeError: Object NOT-A-BUFFER has no method 'push'

There is a section of my site that is not located on ember, but where it would be convenient to use one of the steering templates served through the asset pipeline.

OK This is really easy to do by simply not contacting Ember.TEMPLATES directly. Instead, use Ember.View and call appendTo () directly to render. For instance:

 App = Ember.Application.create({}); var view = Ember.View.create({ templateName: "views/wanderlists/templates/gallery", name: "Bob" }); view.appendTo("#message"); 

A working example is here: http://jsfiddle.net/mgrassotti/VWmFq/1/

See Ember Guides for more details : species definition

+6
source

All Articles