Nested data context in dynamic template

Hi,

I have a dynamic template that is rendering a set of templates in an array, like this:

                    {{#each contentItem in contentItems}}
                      {{> Template.dynamic template=contentItem data=person}}
                    {{/each}}

This works correctly, and my ‘contentItem’ template is rendered. The data context is set to ‘person’ which is an object in the template. ‘person’ has fields like, name, phone, etc.

In my child template, I now have access to {{ name}}, {{phone}}, etc.

What I would really like is to have that data context in the child template to be like {{person.name}}, {{person.phone}} etc, as I use this explicit data context as a standard throughout my app.

I guess I’m looking for something like:

                    {{#each contentItem in contentItems}}
                      {{> Template.dynamic template=contentItem data.person=person}}
                    {{/each}}

or

                    {{#each contentItem in contentItems}}
                      {{> Template.dynamic template=contentItem data={person: person}}
                    {{/each}}

Is there a standard way of achieving this? I suppose I could have a helper that returns a nested object, but I thought maybe there is a better way.

Oh, I guess it is important to note that {{person}} comes from a helper function.

if I try data=data, i do pass my data context properly, but it doesn’t have my ‘person’ object.

Right now I am doign a helper like this:

 parentData() {
      var username = FlowRouter.getParam("username");
      profile = UserProfiles.find({username: username}).fetch()[0];
      return {person: profile};
    }

and the #each like this:

    {{> Template.dynamic template=contentItem
data=parentData}}
  {{/each}}

It seems to work, but maybe there is a better way.

No, you’ve got the best way right there in that helper!