Josip Ivković
Josip Ivković

Reputation: 37

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.

Upvotes: 0

Views: 380

Answers (2)

Chase
Chase

Reputation: 61

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

Upvotes: 0

Josip Ivković
Josip Ivković

Reputation: 37

I've used Template.currentData(); and managed to access the data in template.created but can someone explain why "this" in template.created and template.events refers to 2 different things?

Upvotes: 1

Related Questions