Reputation: 741
I have 2 collections which go as:
Posts = new Mongo.Collection('posts');
Pinned = new Mongo.Collection('pinned');
I want to be able to do this:
{{> posts}}
<template name='posts'>
{{#each posts}}
<!-- code goes here -->
{{/each}}
{{#each pinned}}
<!-- code goes here -->
{{/each}}
</template>
So far I've seen that I can't use data from 2 different collections in the same template. Any ideas how can I achieve this?
Thanks in advance.
Upvotes: 0
Views: 54
Reputation: 1128
I assume you have used publish and subscribe with iron-router. You can achieve your objective in either of the following ways:
Method 1:
Html
<template name="posts">
{{#each posts}}
<!-- code here-->
{{/each}}
{{#each pinned}}
<!-- code here -->
{{/each}}
</template>
Js
Template.posts.helpers({
posts : function(){
return Posts.find().fetch();
},
pinned : funcion(){
return Pinned.find().fetch();
}
});
Method 2:
Html
<template name="posts">
{{#each posts}}
<!-- code here -->
{{/each}}
{{> pinned}}
</template>
<template name="pinned">
{{#each pinned}}
<!-- code here -->
{{/each}}
</template>
Js
Template.posts.helpers({
posts : function(){
return Posts.find().fetch();
});
Template.pinned.helpers({
pinned : function(){
return Pinned.find().fetch();
});
Upvotes: 1