http://www.webtempest.com/meteor-js-autoform-tutorial
有这些简单的文件:main.html:
<head>
<title></title>
</head>
<body>
<div class="container">
<h1>Posts</h1>
{{> quickForm collection="Posts" id="insertPostForm" type="insert"}}
</div>
<template name="main">
<div class="container">
{{> yield}}
</div>
</template>
</body>
post.html:
<template name="post">
<h1>Edit Post</h1>
{{> quickForm collection="Posts" id="updatePostForm" type="update" doc=this}}
<a class="btn" href="/">Back</a>
</template>
posts.html:
<template name="posts">
<h1>Add Post</h1>
{{> quickForm collection="Posts" id="insertPostForm" type="insert"}}
<ul>
{{#each posts}}
<li><a href="{{pathFor 'post.show'}}">{{title}}</a> - {{content}}</li>
{{/each}}
</ul>
</template>
和路由器:
Router.configure({
layoutTemplate: 'main'
});
Router.route('/', 'posts');
Router.route('/posts/:_id', function () {
var item = Posts.findOne({_id: this.params._id});
this.render('post', {data: item});
}, {
name: 'post.show'
});
当我运行时,我收到此错误:
Error: No Iron.Layout found so you can't use yield! iron_layout.js:410
请问我该怎么做才能解决这个问题?
答案 0 :(得分:2)
main.html中的内容无效。 </body>
标记不应位于布局定义之后。将其更改为:
<head>
<title></title>
</head>
<body>
<div class="container">
<h1>Posts</h1>
{{> quickForm collection="Posts" id="insertPostForm" type="insert"}}
</div>
</body>
<template name="main">
<div class="container">
{{> yield}}
</div>
</template>