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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With