Javascript 流星流路由器嵌套动态模板

Javascript 流星流路由器嵌套动态模板,javascript,meteor,rendering,meteor-blaze,flow-router,Javascript,Meteor,Rendering,Meteor Blaze,Flow Router,我试图在动态模板中呈现一个动态模板 主要布局: <template name="template1"> {{>navbar}} <div class="container"> {{>Template.dynamic template=content}} </div> </template> 我正在尝试渲染template2,在template1的内部,然后我想在template2的内部渲染Tem

我试图在动态模板中呈现一个动态模板

主要布局:

<template name="template1">
    {{>navbar}}
    <div class="container">
        {{>Template.dynamic template=content}}
    </div>
</template>

我正在尝试渲染template2,在template1的内部,然后我想在template2的内部渲染Template3。是否必须先在模板2中渲染模板3,然后才能在模板1中渲染该模板?

您需要使用辅助工具渲染子模板。将路由器代码更改为:

action: function () {
    BlazeLayout.render("template1", {
        content: "template2"
    });
}
您只需要一个呈现调用,因为template2将自动呈现给定的动态模板。现在在template2中创建辅助对象:

Template.template2.helpers({
  dataSection() {
    return "template3";
  }
});

如果需要,您可以使用不同的逻辑替换return语句,只要它返回模板的名称。

您也可以在不使用模板辅助程序的情况下执行此操作:

BlazeLayout.render('App_Body', {main: 'parent', sub: 'details' });
主模板的HTML

<template name="App_body">
   {{> Template.dynamic template=main}}
</template>
然后在详细信息模板JS部分,您可以获得id:

Template.todo.onCreated(function todoOnCreated() {
   var id = FlowRouter.getParam('id');
   // ...
});

好的简单的解决方案。
BlazeLayout.render('App_Body', {main: 'parent', sub: 'details' });
<template name="App_body">
   {{> Template.dynamic template=main}}
</template>
<template name="parent">
    Parent template
    {{> Template.dynamic template=sub}}
</template>
<template name="details">
    Sub template
</template>
FlowRouter.route('/todos/show/:id', {
    name: 'Todo.show',
    action(params, queryParams) {
        BlazeLayout.render('App_body', {main: 'parent', sub: 'details' });
    }
});
Template.todo.onCreated(function todoOnCreated() {
   var id = FlowRouter.getParam('id');
   // ...
});