meteor Blaze Templating Data context of a template


Example

Whenever a template is called upon, the default data context of the template is implicitly gained from the caller as in example the childTemplate gains the data context of the parentTemplate i.e caller template

<template name="parentTemplate">
    {{#with someHelperGettingDataForParentTemplate}}
    <h1>My name is {{firstname}} {{lastname}}</h1>
    //some stuffs here
    {{> childTemplate}}
    {{/with}}
</template>

In the above situation,whatever data the helper extracts for parent template are automatically gained by childTemplate.For example,the {{firstname}} and {{lastname}} can be accessed from childTemplate as well as shown below.

<template name="childTemplate">
<h2>My name is also {{firstname}} {{lastname}}</h2>
</template>

We can even explicitly define the data context of the childTemplate by passsing arguments to the template like in below example.

<template name="parentTemplate">
    {{#with someHelperGettingDataForParentTemplate}}
    <h1>My name is {{firstname}} {{lastname}}</h1>
    //some stuffs here
    {{> childTemplate childData=someHeplerReturningDataForChild}}
    {{/with}}
</template>

Assuming the helper someHelperReturningDataForChild returns object like {profession:"Meteor Developer",hobby:"stackoverflowing"},this particular object will be the explicit data context for the childTemplate. Now in child template we can do something like

<template name="childTemplate">
    <h2>My profession is {{profession}}</h2>
    <h3>My hobby is {{hobby}}</h3>
</template>