繁体   English   中英

Meteor.js使用辅助值作为模板

[英]Meteor.js using value of a helper as template

我想基于一个助手值渲染不同的模板。 我将尝试编写示例。

...
{{#with myHelper}}
 {{> this }}
{{/with}}
...

带有帮助者的定义如下:

...
myHelper : function(){
  return MyCollection.findOne({ userId: Meteor.userId() }).personalizeTemplate; 
}
...

不幸的是,这种方式不起作用。 有什么解决办法吗?

您需要使用动态模板,甚至不需要{{#with}}

{{> Template.dynamic template=myHelper }}

要动态使用模板,您必须使用全局Template.dynamic

{{> Template.dynamic template="my template"}}

{{> Template.dynamic template=myHelper}}

请注意, myHelper必须返回一个字符串,它是模板的名称。
您还可以为data上下文提供data

{{> Template.dynamic template=myTemplate data=someData}}

发现流星写了一篇关于它的文章。 它是在2014年创建的,自整篇文章中使用的UI名称空间已重命名为Template

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM