【问题标题】:Render multiple templates in one layout iron:router在一个布局中渲染多个模板 Iron:router
【发布时间】:2016-04-03 02:08:07
【问题描述】:

我已经盯着这个看了一个小时,并尽可能多地重新输入它,但问题是我只看到 /sites/ 路由上的“社交”模板。

在流星客户端,我正在运行这段代码(使用 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>

绝对没有任何明显的错误,即。模板中的拼写错误,非常感谢任何建议!

【问题讨论】:

  • 你试过{{&gt;yield "top"}}而不是{{&gt;yield top}}

标签: javascript html meteor iron-router


【解决方案1】:

这保持不变:(在客户端和服务器的 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 文件夹 /client 中)

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 2011-04-17
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多