1

I couldnt figure out why my Meteor template helper wasnt working on my Ubuntu server, so I just hacked together a couple variations and this one ended up working...locally I use if(user[0].trusted == true) but for some reason that conditional wasnt getting triggered on the server.

Handlebars.registerHelper('isTrusted', function(user_id){
        var user = Meteor.users.find({_id: user_id}).fetch();

        console.log(user, 'user');
        console.log(user[0].trusted);

        if(user[0].trusted = true){
            console.log(user[0].trusted, 'user trusted field');
            return true;
        } else {
            false;
        }

});

Why?

redress
  • 1,314
  • 3
  • 19
  • 32

2 Answers2

3

Your hack is wrong. It will always enter in the if branch, mostly because you are not comparing but assigning:

if(user[0].trusted = true)

Here you are assigning to user[0].trusted the true value. Because it's inside an if, javascript is checking if the assignment is correct. Because it assigned correctly, then it enters in the branch (always).

Send to console the value of user[0].trusted. Maybe it's a number, or has another value. Anyway, your code has a bug, it's not a thing with the server.

jparaya
  • 1,291
  • 8
  • 14
1

This may be a nice way to do it too:

Handlebars.registerHelper('isTrusted', function(user_id){
    return !!Meteor.users.findOne({_id: user_id, trusted: true});
});

Or if you cast it to a string you can use 'true' instead of true

Tarang
  • 72,789
  • 35
  • 206
  • 268