流星动态创建新模板

Meteor create new template dynamicaly

当应用程序 运行 时,是否可以创建新模板(来自 var 或集合)?

像这样:

MyHtmlTmpl from var or collection > Create new Template.MyNewTmpl > Insert in dom

谢谢

您需要编辑

meteor add spacebars-compiler

那你可以这样写:

function renderTemplateWithData (content, data, parent) {
  var newView = Blaze.With(
    data,
    eval(SpacebarsCompiler.compile(content, { isBody: true }))
  )
  Blaze.render(newView, parent)
}

可以这样使用:

renderTemplateWithData('<h1>{{title}}</h1>', { title : "hello world" }, document.body)