6
votes

I need to evaluate an Ember Template programmatically, so that I can generate the HTML that results by evaluating the Ember template within a supplied context.

I want to use this generated HTML to insert into a google maps InfoWindow (small modal that appears when you click on a marker.)

All of the variables will be unbound.

I have tried

Ember.TEMPLATES['templateName']( {context: 'suppliedHere})

but this expects a Ember.RenderBuffer to exist in the data.buffer object

2
I am having the exact same issue. Have you figured this out yet? - elsurudo
have the same issue here. any suggestions? - Moh
I also have this issue, any ideas? - Ricky Jiao
Hi @ianpetzer, I finally find solution here netguru.co/blog/rendering-templates-strings-emberjs. Hope this could help you and other people! - Ricky Jiao

2 Answers

0
votes

Here's another solution, inside your Ember view/component:

var viewClass = Ember.View.extend({ templateName: this.get('contentTemplate') });
var view = this.createChildView(viewClass);
var html = view.renderToBuffer().buffer;
-2
votes

Ember uses Handlebars.js for templating.

If you have the template as a string you can use Handlebars directly:

var template = 'Hi {{name}}';
var context = {name: 'John'};
Handlebars.compile(template)(context); //returns "Hi John"