particular parameters
particular parameters

Reputation: 23

Can i get the template parent data context in the event function?

I'd love to get my hands on a templates data context. Can I do something like this?

'click .newContext': function(event, template) {
    var template_parent = template.parent();
    var parent_data = template_parent.data;
}

Upvotes: 1

Views: 3263

Answers (2)

Mário
Mário

Reputation: 1612

You can use Template.parentData(0), the argument defines how deep you want to go, if you pass none, 0 is the default. Check the documentation on this: http://docs.meteor.com/#/full/template_currentdata

Upvotes: 3

Scott
Scott

Reputation: 1342

Yeah, if you're trying to get the parent's data context you should be able to use the parentData() method on the Template instance. You probably don't even need that second template parameter.

'click .newContext': function(event) {
    var parent_data = Template.parentData();
}

Upvotes: 0

Related Questions