Reputation: 1217
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.
Upvotes: 14
Views: 11734
Reputation: 1725
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).
Upvotes: 23