How to read precompiled template inside my html


#1

I have a template file precompile.handlebars. Its content is,

<div>Hello {{name}}</div>

I compiled the template in my command line using the command,

ember-precompile precompile.hbs -f precompile.js

The content of the precompile.js file is,

    Ember.TEMPLATES["precompile"] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Ember.Handlebars.helpers); data = data || {};
  var buffer = '', hashTypes, hashContexts, escapeExpression=this.escapeExpression;


  data.buffer.push("<h2>Welcome to Ember.js ");
  hashTypes = {};
  hashContexts = {};
  data.buffer.push(escapeExpression(helpers._triageMustache.call(depth0, "name", {hash:{},contexts:[depth0],types:["ID"],hashContexts:hashContexts,hashTypes:hashTypes,data:data})));
  data.buffer.push("</h2>");
  return buffer;

});

Now i read my precompiled template in my html.

 var temp = Em.TEMPLATES['precompile'];
 var temp_html = temp({name: "Ram Chiranjeevi"});
 $("#testdiv").html(temp_html);

TypeError: Cannot read property ‘push’ of undefined error message is thrown. I need to load the template inside an element in my html.

Thanks Jeevi


#2

You don’t insert the HTML/Template directly. Just load the JS/Pre-compiled template and then set the property “templateName”.


#3

Hello, I have the same problem. What do you mean by setting “templateName” property ? I have in my app.js

 App.IndexView = Ember.View.extend({
  templateName: 'test'
}); 

It’s showing my template (i see text “Hello”) but how do i set variable Name from compiled .js file inside my index.html ?

UPDATE Nevermind now. I’ve figured it myself. For anyone that have the same problem : Nothing needs to be done in index.html besides giving sources to js and css. Everything goes into compiled template and variable name goes to model.