这似乎是一个基本的模板,但我无法让Iron Router在页面上的正确位置呈现我的模板。
在我的路由器控制器中,我有:
Router.configure({
loadingTemplate: 'loading',
notFoundTemplate: 'notFound'
});
Router.map(function () {
this.route('home', {
path: '/',
template: 'home',
layoutTemplate: 'layout'
});
this.route('posts', {
});
this.route('post', {
path: '/posts/:_id'
});
});
在布局html页面中,我有:
<body>
<!-- some other static page stuff here -->
<div class="container">
<template name="layout">
{{yield}}
</template>
</div>
</body>
基本版本的家庭模板看起来像:
<template name="home">
<h1>Home Page</h1>
</template>
我已经尝试了一些变体,但主模板总是在布局模板的底部,就在结束正文标记之前,而不是在div.container 中呈现
您放置的标签有点不正确。
模板需要有自己的&正文标签应为空:
<body>
<!-- There isn't anything here really -->
</body>
<template name="layout">
<div class="container">
{{>yield}}
</div>
</template>
这应该适用于您的home
路由,但不适用于post
路由,因为您没有给它们一个布局模板。
您可以设置一个通用布局,以便它可以在posts
和home
上工作(如果您没有在那里设置布局模板,它会覆盖下面的模板),使用:
Router.configure({
loadingTemplate: 'loading',
notFoundTemplate: 'notFound',
layoutTemplate: 'layout'
});
所以铁路由器将您的布局模板放在身体里为您。