I wanted to display all the user information in a tabular format as a part of an admin page. I used meteor accounts ui package for the same.
The HTML code is:
{{#each userList}}
<tbody>
<tr>
<th scope="row">*</th>
<td>{{infofullname}}</td>
<td>{{infosurname}}</td>
<td>{{infoemail}}</td>
</tr>
</tbody>
{{/each}}
The problem is that the information for the current user is getting displayed and not all the enrolled users. The iteration does happen but for the current logged in user. Also the email address is not getting displayed.
The helper code is:
Template.students.helpers({
userList: function(){
return Meteor.users.find({});
},
infofullname: function(){
return Meteor.user().profile.fullname;
},
infosurname: function(){
return Meteor.user().profile.surname;
},
infoemails: function(){
return Meteor.user().emails.[0].address;
}
});
Im facing the following problems: 1) The email address is not getting displayed. 2)The information of all the users is not getting displayed.
Thank You.
Publish all users with the following on the server:
Meteor.publish('allUsers',function(){
return Meteor.users.find({},{fields: {emails: 1, profile: 1}});
this.ready();
});
Then subscribe on the client with:
Meteor.subscribe('allUsers');
Your helpers will need some slight modifications as @Sudhanshu suggested however since you're looping over a cursor of users you can take advantage of this
being an individual user object inside the loop.
Template.students.helpers({
userList() {
return Meteor.users.find({});
},
infofullname() {
return this.profile.fullname;
},
infosurname() {
return this.profile.surname;
},
infoemails: function(){
return this.emails.[0].address;
}
});
You can also access nested properties directly in blaze, avoiding the need for three of your helpers, ex:
{{#each userList}}
<tbody>
<tr>
<th scope="row">*</th>
<td>{{profile.fullname}}</td>
<td>{{profile.surname}}</td>
<td>{{emails.[0].address}}</td>
</tr>
</tbody>
{{/each}}