Passing multiple objects to a Dynamic Template

So what I am trying to do is pass in the current field as well as the current section in each loop to a dynamic template. I know that meteor has the .. syntax to access the parent within the fields loop but I cannot figure out how to pass both this and .. any ideas?

{{#with form}}
        {{#each sections}}
          <div class="panel panel-default">
            <div class="panel-heading">{{name}}</div>
              {{#each fields}}
                  {{> Template.dynamic template=type data=this }}
              {{/each}}
          </div>
        {{/each}}
    {{/with}}

There must be a better way but this was my solution for now

{{#with withParent ..}}
 {{> Template.dynamic template=field.type data=this }}
{{/with}}

And the withParent helper looks like so

Template.viewFormFields.helpers({
  'withParent' : function (parent) {
    return { field : this, sections : parent };
  }
});
1 Like

From what i seem to understand, all of this will change in the near future.

I haven’t heard, how will things change?

I think the way the context will be handled will be different. I can’t seem to get back a hand on the documents explaining these changes.

Thanks. Do you know what version these changes are expected?

I dunno.
I think there will be changes to helpers arguments in the next version, but i’m not sure if the context modifications will be included, i guess this is not a light (=breaking) change.

if you look at Spacebars’ current devel branch README, you would see that 2 new blocks are being introduced in the next version - {{#let}} and {{#each item in items}}

I’m counting on these new blocks to simplify your problem and similar others

1 Like