How to insert {{username}} into Posts collection

Hello there.

I am using useraccounts (with bootstrap and iron:router) for my accounts system. My users sign up with their usernames, not email.

My app has a form that populates the Posts collection when submitted. And I can display all my data on the template.

Now, for each posts, I want to display the respective user who submitted the post as {{username}}.
The {{username}} expression currently displays nothing.

This is my template event helper.

 Template.submit.events({
"submit .newarguement": function(event) {
    var name = event.target.name.value;
    var arguement = event.target.arguement.value;
    var tag1 = event.target.tag1.value;
    var tag2 = event.target.tag2.value;
    var tag3 = event.target.tag3.value;
    var file = $('#productImage').get(0).files[0];
    if (file) {
        fsFile = new FS.File(file);
        ArguementCollection.insert(fsFile, function(err, result) {
            if (!err) {
                var productImage =
                    '/cfs/files/ArguementCollection/' +  result._id;
                Posts.insert({
                    name: name,
                    arguement: arguement,
                    tag1: tag1,
                    tag2: tag2,
                    tag3: tag3,
                    image: productImage
                });
            }
        });
    } else {
        var productImage = '/img/empty.jpg';
        Posts.insert({
            name: name,
            arguement: arguement,
            tag1: tag1,
            tag2: tag2,
            tag3: tag3,
            image: productImage
        });
    }

    event.target.arguement.value = "";
    event.target.tag1.value = "";
    event.target.tag2.value = "";
    event.target.tag3.value = "";
    
    Router.go('/');
    return false;
}
 });  

Right now, {{username}} displays nothing.
I have not figured out how to accomplish this. Any help will be appreciated.

If you are trying to get your own user name you can use Meteor.user() to find the user object, and/or Meteor.user().username for just the name.

If you are trying to get another user, you can use Meteor.users.find({ }) to find the user object - just like any other MongoDB query. Or Meteor.users.find({ }).username for the name.

@Spyridon thanks. it worked

1 Like