未捕获的错误:未找到Iron.Layout,因此您无法使用yield [英] Uncaught Error: No Iron.Layout found so you can't use yield

查看:85
本文介绍了未捕获的错误:未找到Iron.Layout,因此您无法使用yield的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Meteor 0.9.3和iron:router 1.0.0-pre2,即使安装了iron:layout,控制台上也会显示此错误,请参见以下内容:

Using Meteor 0.9.3 and iron:router 1.0.0-pre2, this error shows on the console even though iron:layout was installed, see below:

willems-mini:iron willem$ meteor add iron:router@=1.0.0-pre2
added iron:location at version 1.0.0-pre2
added iron:dynamic-template at version 1.0.0-pre2
added iron:router at version 1.0.0-pre2
added iron:layout at version 1.0.0-pre2
added iron:middleware-stack at version 1.0.0-pre2
added iron:url at version 1.0.0-pre2
added iron:controller at version 1.0.0-pre2
added iron:core at version 1.0.0-pre2

iron:router: Routing specifically designed for Meteor

没有其他软件包,只有流星的默认软件包:

There are no other packages, just the defaults for meteor:

willems-mini:iron willem$ meteor list
autopublish      1.0.0  Publish the entire database to all clients
insecure         1.0.0  Allow all database writes by default
iron:router      1.0.0-pre2  Routing specifically designed for Meteor
meteor-platform  1.1.1  Include a standard set of Meteor packages in your app

我正在尝试运行一个非常简单的应用程序:

I am trying to run a very simple app:

1个javascript文件:

1 javascript file:

Router.route('/', function () {
    this.render('home');
});

if (Meteor.isClient) {
    Template.home.events({
        'click button': function () {
            console.log('click!');
        }
    });
}

和1个html文件:

<head>
    <title>iron router test</title>
</head>

<body>
    {{> defaultLayout}}
</body>


<template name="defaultLayout">
    <header>
        {{> yield "header"}}
    </header>

    <article>
        {{> yield}}
    </article>

    <footer>
        {{> yield "footer"}}
    </footer>
</template>


<template name="home">
    {{#contentFor "header"}}
        <button>click header</button>
    {{/contentFor}}

    <button>click</button>

    {{#contentFor "footer"}}
        <button>click footer</button>
    {{/contentFor}}
</template>

推荐答案

这不是iron:router布局应该起作用的方式.

This is not how iron:router layouts are supposed to work.

摆脱对布局的明确包含:

Get rid of your explicit inclusion of the layout in the body :

{{! this is WRONG, remove the body tag altogether }}
<body>
    {{> defaultLayout}}
</body>

您指定layoutTemplate的位置在RouteController中:

Router.route('/', function () {
  this.render('home');
},{
 layoutTemplate:"defaultLayout" 
});

明确声明RouteController通常是一种更好的设计模式.

Declaring explicitly your RouteControllers is usually a nicer design pattern.

lib/router.js

Router.route("/",{
  // give the route a name so it figures out itself to use :
  // - HomeController
  // - a template name "home"
  name:"home"
});

lib/controllers/lib/default-layout.js

DefaultLayoutController=RouteController.extend({
  layoutTemplate:"defaultLayout"
});

lib/controllers/home.js

HomeController=DefaultLayoutController.extend({
  //
});

这篇关于未捕获的错误:未找到Iron.Layout,因此您无法使用yield的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆