【问题标题】:Subparts for templates with Meteor & BlazeMeteor & Blaze 模板的子部分
【发布时间】:2017-04-14 14:31:05
【问题描述】:

您好,我正在使用 Meteor & Blaze。

我的路线如下所示:

FlowRouter.route('/software', {
    name: 'software',
    action(params, queryParams)
    {
        BlazeLayout.render('App_body', {main_content: 'software_page'});
    }
});

在 App_body 中,我使用 main_content(包含模板的名称),如下所示:

{{> Template.dynamic template=main_content}}

但现在我意识到我喜欢在 App_body 中插入不仅仅是“main_content”。有没有办法为每个模板定义子部分,并引用它们,因为这将代表我的逻辑连接,我有。

【问题讨论】:

    标签: javascript meteor meteor-blaze


    【解决方案1】:

    blaze-layout 自述文件顶部有一个使用动态模板的示例:

    html:

    <template name="layout1">
      {{> Template.dynamic template=top}}
      {{> Template.dynamic template=main}}
    </template>
    
    <template name="header">
      <h1>This is the header</h1>
    </template>
    
    <template name="postList">
      <h2>This is the postList area.</h2>
    </template>
    
    <template name="singlePost">
      <h2>This is the singlePost area.</h2>
    </template>
    

    现在您可以在渲染布局的同时在第二个参数中输入多个模板名称,这是一个对象,其中每个键指定一个模板名称。

    js:

    BlazeLayout.render('layout1', { top: "header", main: "postList" });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-24
      • 1970-01-01
      • 2016-11-19
      • 2016-03-04
      • 2019-02-02
      • 1970-01-01
      • 2014-05-09
      • 2017-07-09
      相关资源
      最近更新 更多