Can someone give an example of how to display an image using collectionFS and reywood:publish-composite? I am using template ready subscriptions. I am displaying small profile images from my ProfileImages collectionfs and the profileImages-sm store of that collection. When image was uploaded, I previously saved off the key of the image document to Meteor.users. I am publishing using reywood:publish-composite.
Meteor.publishComposite('postDivisions', function(lim) {
return {
find: function() {
return Posts.find({}, { sort: { p_inc: -1 }, limit: lim });
},
children: [
{
find: function(post) {
return Meteor.users.find(
{ _id: post.poster_id },
{ limit: 1, fields: { username: 1, profile:1 } });
},
children: [
{
find: function(user) {
return ProfileImages.find({_id:user.profile.image_storeId});
}
}
]
}
]
}
});
and in my html posted template:
{{#if Template.subscriptionsReady}}
{{#each eightPosts}}
<a class="pull-left" href="#">
{{#with postimg}}
<img src="{{this.url store='profileImages-sm'}}" class="proimg" />
{{/with}}
</a>
<div class="media-body">all my thoughts</div>
{{/each}}
{{else}}
Loading...
{{/if}}
and my js file:
Template.posted.onCreated(function () {
var self = this;
self.autorun(function() {
self.subscribe('postDivisions', 8);
});
});
Template.posted.helpers({
eightPosts: function() {
return Posts.find();
},
postimg: function() {
var user = Meteor.users.findOne(this.poster_id);
return ProfileImages.findOne({_id:user.profile.image_storeId});
}
});
Can’t seem to find the how to display the image in the html. I tried using {{#with postimg.profile}}
, but no luck. Otherwise, I am getting an error: Exception in template helper: TypeError: Cannot read property 'profile' of undefined
. Can someone please help me with the correct syntax? Thanks!