var template = this.container.lookup('template:greeting');
You can’t do anything useful with it, like render to a string.
It would make sense to be able to do: template({msg: 'hi'});
Because then the precompiled templates could be used with other libraries that utilise templating, for example Typeahead.js
(I’ve looked everywhere for a solution, including all the tests in github - but these all pass the template into a view, insert it into the DOM and then read the html which seems a waste of effort)
@jasonmit’s will definitely work, but if you do not want to render to the DOM, you can render to a Ember.RenderBuffer instance instead.
See:
function templateToString(template) {
var View = Ember.View.create({ template: template });
var buffer = new Ember.RenderBuffer();
view.render(buffer)
return buffer.string();
}
Oh yes it’s possible under the hood - you have to collate some variables and pass them in, but even then the result is pushed to a buffer rather than returning a value.
You also can’t create a view on its own like your suggestion, due to this. Which means you have to create an empty and unnecessary view file as well in order for the lookup to work.
From your example, I get “You can’t use appendChild outside of the rendering process” or " Container was not found" depending on how I instantiate the view.