How can I use templates outside of the render pipeline

I have an event where I need to insert a template into space outside of the app. With Ember-CLI we have all these wonderfully pre-compiled templates, so I'm trying to figure out how I can use one.

(Ember-CLI 0.0.42, Ember 1.7.0)

I found I can get the pre-compiled template function like this:

import TheTemplate from 'app/templates/the-template';

However, if I call it as documented on the Handlebars website, I get an error.

var context = { button: "OK" };
var str = TheTemplate(context);

Uncaught TypeError: Cannot read property 'push' of undefined

So what is the proper way to use these templates?


This question, asked in a different way, may have been answered already:

Compile Ember template string and running it programmatically, without an Ember application?

Using both a template and view, something like this would seem to work from within another view:

externalView = this.get("container").lookup("view:the-template");
externalView.setProperties({ button: "OK" });
externalView.appendTo($("#here"));

...and then remember to destroy() or destroyElement() later on.

链接地址: http://www.djcxy.com/p/73462.html

上一篇: 即使使用三个大括号,也不会在Handlebars模板中执行<script>标记

下一篇: 我如何在渲染管道之外使用模板