Calculate Ember pattern programmatically

I need to evaluate the Ember Template programmatically, so that I can generate the HTML that is obtained by evaluating the Ember Template in the supplied context.

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

All variables will be unbound.

I tried

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

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

+6
source share
2 answers

Here is 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; 
0
source

Ember uses Handlebars.js for templates.

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

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

Source: https://habr.com/ru/post/946674/


All Articles