Spacebars.compile未定义

时间:2014-08-23 00:57:15

标签: meteor meteor-blaze

我正在尝试在服务器端手动编译一些模板(以电子邮件形式发送)。但是,未定义Spacebars.compile。当我在控制台上打印Spacebars对象时,我得到以下内容:

 { include: [Function],
   mustacheImpl: [Function],
   mustache: [Function],
   attrMustache: [Function],
   dataMustache: [Function],
   makeRaw: [Function],
   call: [Function],
   kw: [Function],
   SafeString: [Function],
   dot: [Function],
   TemplateWith: [Function],
   With: [Function] }

我做错了吗?请注意,我已尝试手动包含spacebars-compile包,但没有显示。

编辑:代码示例

function renderTemplate (template, data) {
    var compiled = Spacebars.compile(template, data);
    var render = new Function("return " + compiled)();

    var tpl = UI.Component.extend({
        kind: "dynamicTemplate",
        render: render
    });

    return tpl;
};

我得到#< Object> .compile未定义

1 个答案:

答案 0 :(得分:0)

[这个答案已知对Meteor版本1.1.0.2有效]

首先,您需要添加spacebars-compiler package

meteor add spacebars-compiler

然后将您的调用更改为使用SpacebarsCompiler.compile()