How to display all the registered users in a list with their profile data in Meteor?

Currently i can display all the registered users only with their username. How can i get other users info like email, profile data(name, profile image etc.)

{{#each users}}
        <div class="authorList">
            <h3>{{username}}</h3>
            <h3>{{user.email}}</h3>
            <h3>{{user.profile.first_name}}</h3>    
            <h3>{{user.last_name}}</h3> 
            <img src="{{user.profilePic}}">
        </div>
    {{/each}}

Here is the router code passing data using iron:router.

// Authors List Route
this.route('authors',{
    path: '/authors',
    template: 'authors',
    data: function(){
        templateData={
            users: Meteor.users.find()  
        };
        return templateData;
    } 
});

First, enter Meteor.users.find().fetch() in the browser console. This will show you all the information that the client currently has access to, and give you a look at how the data is structured.

I assume for this demo that profilePic is just a url to an image on the internet or one you’ve put in the public folder. For proper image/file management you need to add a package like CollectionFS.

Btw, you forgot to put var before templateDate={… in the route. That makes me suspect you’re not using a linter in your text editor. Get one! It’ll make coding so much easier, pointing out all your minor errors right away.

These are some different valid options you could write your template:

{{#each users}}
        <div class="authorList">
            <h3>{{username}}</h3>
            <h3>{{profile.email}}</h3>
            <h3>{{profile.first_name}}</h3>    
            <h3>{{profile.last_name}}</h3> 
            <img src="{{profile.profilePic}}">
       </div>
{{/each}}
{{#each users}}
        <div class="authorList">
            <h3>{{this.username}}</h3>
            <h3>{{this.profile.email}}</h3>
            <h3>{{this.profile.first_name}}</h3>    
            <h3>{{this.profile.last_name}}</h3> 
            <img src="{{this.profile.profilePic}}">
       </div>
{{/each}}
{{#each users}}
        <div class="authorList">
            <h3>{{username}}</h3>
            {{#with profile}}
                 <h3>{{email}}</h3>
                 <h3>{{first_name}}</h3>    
                 <h3>{{last_name}}</h3> 
                 <img src="{{profilePic}}">
            {{/with}}
       </div>
{{/each}}
1 Like

It worked! Thanks a lot!