[solved] Data flow between parent and child templates


#1

Say you have two templates, one being a parent of the other like this:

<template name="parent">
  {{> child }}
</template>

<template name="child">
</template>

If the parent template is subscribed to publication1, (if I’m not mistaken) the child can also access the data context. And if the child is subscribed to a publication2, does this cause some kind of interference or confusion on which data the child should use?

Note: the publications return data from different collections (e.g. in a health-industry type of app, publication1 returns a patient from a Patients collection and publication2 returns the given patient’s treatment history from a Treatments collection)


#2

It’s not the subscription itself that sets the data context but the helper. So if the parent subscribes to widgets and binds a list element to a widget via a helper then, absent anything else, if the list item is a child template it will have the data context of the widget no matter what it subscribes to.

Subscriptions control what data is available on the front end, not what actually gets rendered. It’s the helpers that do that…

I’m a bit rusty in Blaze having been coding with another view library in the last few months so happy to be corrected.


#3

That makes a lot of sense. It’s clarified a lot about how subscriptions work for me. I guess my understanding of them before was flawed. I’ve been trying to display return data from Template.rendered, and I couldn’t understand why it wasn’t working.