Search code examples
meteoriron-routermeteor-blaze

Meteor: Pulling variable from iron router to a template


I am trying to get two variable from the iron router so that I can essentially call them in my temlate such as {{user.telephone}} and {{pic.profilepic}}. My code in the router is as follows. (Does Not Work!)

Router.route('/profile/:_id', {
name: 'profile',
template: 'profile',
data:function(){
    return {
        user:Info.findOne({_id:this.params._id}),
        pic: Profilepics.findOne({_id:this.params._id})
    };
   },
subscriptions: function(){
    return {
        Meteor.subscribe("userInfo"),
        Meteor.subscribe( "profilepic");
},
action:function (){
    if (this.ready()){
        this.render();
    }else {
        this.render('loading');
    }
  }

});

I able to do just one variable with the following code. i.e get {{user.telephone}}. Any chance anyone can help me get both variable instead of just one?

enterRouter.route('/profile/:_id', {
name: 'profile',
template: 'profile',
data:function(){
    return {
        user:Info.findOne({_id:this.params._id})
    };
   },
subscriptions: function(){
    return Meteor.subscribe("userInfo")
},
action:function (){
    if (this.ready()){
        this.render();
    }else {
        this.render('loading');
    }
  }
 }); 

Solution

  • Return multiple subscriptions as an array from subscriptions function,

    Use return [ Meteor.subscribe("userInfo"), Meteor.subscribe( "profilepic") ];

    instead of

    return { Meteor.subscribe("userInfo"), Meteor.subscribe( "profilepic"); which has {} mismatch.