How to parse user profiles on a template?


#1

I have created a test app with user account-password and accounts-ui bootstrap and alanning roles, after I registered my account, i updated my user fields on meteor mongo shell, update role as admin. My problem is, how do i parse my data (profile) on a template?

I have this on my template

    {{#each users }}
          <tr>
              <td>{{profile.company}}</td>
              <td>{{profile.branch}}</td>
              <td>{{email}}</td>
              <td>{{password}}</td>
              <td>{{roles}}</td>
              <td>{{username}}</td>
              <td>&nbsp;</td>
        </tr>
 {{/each }}

on my server

Meteor.publish('users', function () {
    return users.find({});
});

on both clinet.server controller.js

UsersController = AppController.extend({
	waitOn: function() {
    return this.subscribe('users');
  },
  data: {
    users: users.find({})
  },
  onAfterAction: function () {
    Meta.setTitle('Users');
  }
});

UsersController.events({
  'click [data-action=doSomething]': function (event, template) {
    event.preventDefault();
  }
});

By the way, the roles and username are all parsing correctly for the current logged in user on the header.

{{currentUser.username}}<br> {{currentUser.roles}}

and then eventually, if the user profile successfully parsed, i can edit it as admin.

Adding user is next on my roadmap, i have to make this work before I move on to another.


#2

What’s not working? What’s your question?


#3

Thanks and I appreciate your response. Actually, my question is it’s in the topic title itself. Anyway, the problem is how to parse/display the user data (profile) on a template? I know i am missing something on the code above, i need help! Thanks


#4

You are displaying the data in a template on the code above, aren’t you? Does your code above work? If no, what’s happening?


#5

It’s partially working now, i modified my template code to:

{{#each users }}
                <tr>
                  <td>{{profile.company}}</td>
                  <td>{{profile.branch}}</td>
                  <td>{{emails}}</td>                 
                  <td>{{roles}}</td>
                  <td>{{username}}</td>
                  <td>&nbsp;</td>
                </tr>
                {{/each }}

my publishing code to:

Meteor.publish('users', function () {
    return Meteor.users.find({});
});

I commented the helpers.

Because i have this on my controllers:

UsersController = AppController.extend({
  data: {
    users: Meteor.users.find({})
  },
  onAfterAction: function () {
    Meta.setTitle('Users');
  }
});

UsersController.events({
  'click [data-action=doSomething]': function (event, template) {
    event.preventDefault();
  }
});

It did display the company, branch, roles and username but on emails it says [object Object].

How do i fix the email issue?

Thanks!


#6

I already fixed the issue, it should be {{emails.[0].address}} to properly display the users email.

Thanks!