Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access parent data context in Template rendered function in Meteor

I have the following parent template:

<template name="parentTempl">
    {{#each child}}
       {{> childTempl}}
    {{/each}}
</template>

I want to access the parent data context in childTempl:

Template.childTempl.rendered = function() {
    console.log(this.parent.data); // ?
};

How can I do this? Any help would be greatly appreciated.

like image 702
user3475602 Avatar asked Nov 06 '14 06:11

user3475602


1 Answers

You can use Template.parentData(n) to access the parent context inside any template helper or rendered callback. See the docs here. Internally, all it does is call the Blaze getView method for the parent view until it hits the desired parent context (as defined by n).

like image 173
mark Avatar answered Nov 01 '22 09:11

mark