在一个布局铁中渲染多个模板:路由器

Render multiple templates in one layout iron:router

本文关键字:路由器 一个 布局      更新时间:2023-09-26

我已经盯着它看了一个小时了,并尽可能多地重新键入了它,但问题是我只在/sites/routing上看到了"社交"模板。

在流星客户端,我正在运行以下代码(使用iron:router)

    Router.configure({
      layoutTemplate: 'ApplicationLayout'
    });
    Router.route('/', function () {
      this.render('welcome', {to:"main"});
    });
    Router.route('/sites/', function () {    
      this.render('social', {to:"main"});
      this.render('websiteaddform', {to:"top"});
    });

在HTML方面,这里是布局模板:

<template name="ApplicationLayout">
    <header>
        {{>yield top}}
    </header>
  {{>yield main}}
</template>

绝对没有任何明显的错误,即模板中的打字错误,任何建议都非常感谢!

这保持不变:(在客户端和服务器的Lib文件夹中的router.js中)

    Router.configure({
    layoutTemplate: 'ApplicationLayout'
  });
  Router.route('/', function () {
    this.render('welcome', {to:"main"});
  });
  Router.route('/sites/', function () {
    this.render('social', {to:"main"});
    this.render('websiteaddform', {to:"top"});
  });

这里你忘记了"引号"(在applicationlayout.html文件夹/客户端中)

<template name="ApplicationLayout">
    <header>
        {{>yield "top"}}
    </header>
  {{>yield "main"}}
</template>

为了完成它,我添加了一个示例模板:(文件夹/client/templates中的文件templates.html)

<template name="welcome">
  welcome
</template>
<template name="social">
  social
</template>
<Template name="websiteaddform">
  websiteaddform
</Template>