Reputation: 10608
I have a Meteor project with a profile page system setup for each user which I created with the help of this question.
How can I retrieve information from the user's profile for that page in the JS code for my Template.helpers?
Eg. I have the following helper for my profile page
Template.profile.helpers({
winLoseRatio: function() {
var wins = 0;
var losses = 0;
var ratio = wins/losses;
ratio = Math.round((ratio * 1000) + 0.000001) / 1000;
return ratio;
},
totalGuesses: function() {
var wins = 0;
var losses = 0;
var total = wins + losses;
return total;
}
});
For all the values of 0, I want to get the user's (who's profile I'm on) .profile.stats.wins and .profile.stat.losses field values.
I tried Meteor.userId().profile.stats.wins
but that returned the wins of the current logged in your and not the wins of the user who owns the profile page.
Upvotes: 1
Views: 398
Reputation: 4094
All users are available in Meteor.users
collection, so:
// Find user with id of currently viewed profile.
var user = Meteor.users.findOne(userId);
if (user) {
console.log(user.profile.stats.wins);
} else {
console.log('No user with id', user);
}
Upvotes: 3