我有'postlist'模板上的名稱列表。這些是創建帖子的人的「用戶名」。我創建了一個href鏈接,以便當用戶點擊該名稱時,它們被路由/定向到一個新的模板'viewpost'並能夠查看完整的文章文檔。流星:模板內的渲染模板
但是,我希望將'viewpost'模板渲染到我已將{{> yield}}放入'postlist'模板中的位置。如何配置layourTemplate,因爲我已經有一個應用程序的另一部分工作。
當然,這個帖子文件顯然應該根據用戶點擊的名字來改變。
想象流星todos的例子。根據您點擊「加入」還是「登錄」,相關模板會被渲染。
所以我到目前爲止如下。
postlist.html(顯示發佈文檔中'全名'字段的列表)。
<template name="postlist">
<div class="container">
<div class="col-sm-3">
{{#each post}}
<li><a href="{{pathFor 'viewpost'}}" >{{fullname}}</a></li>
{{/each}}
</div>
</div>
{{> yield}}
</template>
router.js
Router.map(function(){
this.route('postlist',{
path: '/postlist',
template: 'postlist',
waitOn: function(){
return Meteor.subscribe('posts');
},
data: function(){
return {post: Posts.find({})};
}
});
this.route('viewpost',{
path: '/viewpost/:_id',
template: 'viewpost',
waitOn: function(){
return Meteor.subscribe('posts');
},
data: function() { return Posts.findOne(this.params._id); }
});
});
您可以創建'yield region ='post_body''並呈現到該區域。在這裏閱讀更多信息http://www.manuel-schoebel.com/blog/iron-router-tutorial – yoK0 2014-10-17 18:36:58