Pass data from router into template helper


#1

How can data from Router.route be passed onto a template helper. So I want to use a user _id from my iron router to be used in my template helper to get documents for that particular user. This is the code:

Router.map(function() {
    this.route('/user/:_id', {
    template: 'userPage',
    data: function(){
        var currentList = this.params._id;
        return Meteor.users.findOne({ _id: currentList });
     }
  });
});

So how can the currentUser in the templates.js file be assigned with the value of currentList from the routes.js file?

Template.userPage.helpers({
    name: function () {
        var currentUser = this.currentList; 
        console.log(currentUser);
        var user = Meteor.users.findOne({ _id: currentUser });
        return user.usernamex;
    }
});

Currently it returns undefined

Thanks


#2

FWIW the following says that Router.map is deprecated…


#3

Thanks…I’ll make the changes from Router.map