Search code examples
javascriptmeteoriron-router

Meteor getting data from router


I'm having trouble getting data from iron:router. Im trying to get the data by param._id and then pass it to my template.created to set a session variable for editing purposes.

Here is my code in the router:

Router.route('/edit/:_id', function(){
    this.render('edit', {
        data: function(){

                return Collection.findOne({_id: this.params._id})
        }
    })  
})

And then I want to access that data here:

Template.edit.created = function(){

   data = ???
   Session.set('edit', data)
   $(input).val(data.post)

}

If i do console.log( this ) I get Blaze.TemplateInstance.

But when I console.log(this) in Template.edit.events I get the document I want from the iron:router.


Solution

  • For template.created and template.rendered you can access the data with this.data.