Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates meteor从变量实例化模板_Templates_Meteor - Fatal编程技术网

Templates meteor从变量实例化模板

Templates meteor从变量实例化模板,templates,meteor,Templates,Meteor,我在JS中有一个变量,例如currentPage 现在我想做一些类似的事情: {{> currentPage}} Handlebars.registerHelper('currentPage', function(context, options) { var currentPage = ...; return Handlebars._defaultHelpers(">",currentPage); } Handlebars.registerHelper('curre

我在JS中有一个变量,例如currentPage

现在我想做一些类似的事情:

{{> currentPage}}
Handlebars.registerHelper('currentPage', function(context, options) {
   var currentPage = ...;
   return Handlebars._defaultHelpers(">",currentPage);
}
Handlebars.registerHelper('currentPage', function(context, options) {
    var currentPage = ...;
    document.body.appendChild(Meteor.render(Template[currentPage]));
    return "";
});
当然,这是行不通的

实际上,我想写一个把手助手,如下所示:

{{> currentPage}}
Handlebars.registerHelper('currentPage', function(context, options) {
   var currentPage = ...;
   return Handlebars._defaultHelpers(">",currentPage);
}
Handlebars.registerHelper('currentPage', function(context, options) {
    var currentPage = ...;
    document.body.appendChild(Meteor.render(Template[currentPage]));
    return "";
});
但不幸的是“>”没有注册为Handlebar中的helper函数,我不知道如何访问此代码

我还可以想象使用这样的东西:

{{> currentPage}}
Handlebars.registerHelper('currentPage', function(context, options) {
   var currentPage = ...;
   return Handlebars._defaultHelpers(">",currentPage);
}
Handlebars.registerHelper('currentPage', function(context, options) {
    var currentPage = ...;
    document.body.appendChild(Meteor.render(Template[currentPage]));
    return "";
});
哪种方式有效,但会破坏更新系统

如果我返回一个HTML字符串,模板将不再更新


我认为这很常见,但我不知道如何解决这个问题。

在没有
标记的情况下进行操作。这是路由器中定义的方法
renderPage
helper,或熨斗路由器中的
yield

html:

{{currentPage}}
js:


如果不需要,可以省略
templateData
部分。

那么是否要根据变量呈现模板?您是否考虑过使用路由,比如路由可能是一个选项,如果您只想在“currentPage”这样的全局示例中使用它,但实际上我想在同一个页面上多次使用它,具体取决于我存储在会话变量中的变量。这实际上对于路由以外的一些事情很有用,并且可以存在于典型的路由器上。我在布局、非内容页面区域、模式窗口等应用程序中使用这种方法,在这些应用程序中,我还使用meteor router或iron router来管理内容区域。+1这是正确的方法,没有那么好的文档记录。Thx伙计们,我今天晚些时候会查看它。到目前为止看起来不错!