1

我需要在我的 ember 项目中使用一些预编译的车把模板以及我的普通组件和模板。我已经ember-cli-build.js使用app.import(). 预编译的模板现在显示在对象中,我在我的 Ember文件中Handlebars.templates映射到应用程序声明和应用程序初始化之间。Ember.TEMPLATES["precompiled-template"]app.js

当我检查Ember.TEMPLATES对象时,预编译的模板作为表单的函数存在,function(context, options)与其他模板不同的是对象。

当我尝试使用预编译的模板时,什么也没有出现。有什么想法吗?

编辑1:我说的是小ui模板而不是整个路由模板,我愿意牺牲绑定。

4

1 回答 1

0

I figured out a way to use a helper to convert the handlebars templates to a string and creating a document fragment.

import Ember from 'ember';

export function helper(data/*, hash*/) {
  let precompiledTemplateFunction = Handlebars.templates[data[0]];
  return fragmentFromString(precompiledTemplateFunction());
}

function fragmentFromString(strHTML) {
  return document.createRange().createContextualFragment(strHTML);
}

export default Ember.Helper.helper(helper);

usage: {{helper 'precompiledTemplate'}}

I'm importing the templates in the ember-cli-build.js file app.import('vendor/path/to/precompiled/template');

I haven't dealt with passing in attributes through the helper but I don't think it will be that hard.

于 2016-04-06T16:27:43.930 回答