My application uses iron router: When a user hits a certain route that contains a wildcard, I would like to use the value of the wildcard to call a meteor method and have its return value be used to set the data context for the template.
Example:
Meteor method:
getUserName: function(id){
return Meteor.users.findOne({_id: id}).profile.name;
}
Router:
data: function(){
Meteor.call('getUserName', this.params.userId, function(error, result){
});
}
The meteor method returns the correct value and I can access that value in the callback function. But my problem is that I don't know how to actually use that data. Just returning it from the callback doesn't work.
What is the right way to do this? Or is it not a got idea at all to call a Meteor method in this case? What is the alternative then?
Thank you very much for your answers!