我的流星应用程序有一个像这样的base.html文件:
<head>
<title>MyApp</title>
</head>
<body>
<template name="bodyContent">
{{subContent}}
</template>
</body>接下来,我定义了三个不同的模板:
<template name="templateA">Some text</template>
<template name="templateB">Bla bla bla</template>
<template name="templateC">Your highscore is {{score}}</template>如何使{subContent}能够在运行时在这三个模板之间交替使用?
类似于:
currentTemplateUsed = 'templateB'
Template.bodyContent.subContent = Template[currentTemplateUsed]但这不管用。还有其他方法来实现这一功能吗?
发布于 2012-11-28 20:05:49
您应该使用流星路由器,它能够动态地更改模板。可能的缺点是,它一次只能更改一个模板。
或者,在Meteor的车把上有一些信息:https://github.com/meteor/meteor/wiki/Handlebars
基本上,您必须使用模板作为函数,并将数据传递给它,以便工具栏解析它,如下所示:
var currentTemplateUsed = 'templateC';
var data = {
score : 12
}
Template.bodyContent.subContent = Template[currentTemplateUsed](data);返回Your highscore is 12
发布于 2012-12-18 02:50:38
<body> ... </body>中的模板似乎不起作用,我无法在里面传递数据。我可能错了,但我不得不把它放在外面,然后用:
<body>
{{> body_content}}
</body>https://stackoverflow.com/questions/13610465
复制相似问题