I'm trying to display the number of users in my footer and I would like this number in real time. I think the proper way is to create a publication in the server and to subscribe from the client.
// server/publications.js
Meteor.publish("usersCount", function () {
return Meteor.users.find();
});
// client/main.js
UsersCount = new Meteor.Collection("usersCount");
Meteor.subscribe('usersCount', [], function() {
console.log('subscribed.');
});
// client/views/layout/footer.js
Template.footer.helpers({
famecoiners: function(){
return UsersCount.find().count();
}
});
// client/views/layout/footer.html
<span>{{famecoiners}} Famecoiners!</span>
In the chrome console, we can see the 'subscribed' string from the callback function. The problem is: {{famecoiners}} always returns 0 in my template.