Template.body.helpers({username:function(){
If (Meteor.user()){
return Meteor.user().emails[0].address;
}
else {
return "anonymous internet user";
}
}
});
Gives me an error of
While processing files with ecmascript (for target web.browser):
client/main.js:14:19: Unexpected token, expected ; (14:19)
What am I missing out?
Your JavaScript is malformed. If you’re not using a linter, I’d strongly recommend doing so.
Template.body.helpers({
username:function(){
if (Meteor.user()){
return Meteor.user().emails[0].address;
} else {
return "anonymous internet user";
}
},
anotherhelper:function(){
//some code
}
});
Your code and his code are isomorphic from a code structure point of view.
The mistake is the ‘if’ which is written with an upper case in the first code snippet
If (Meteor.user()){
the compiler doesn’t recognize the keyword ‘if’ and think instead that it’s a variable, a function or an object.