Passing multiple objects to a Dynamic Template


#1

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}}

#2

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 };
  }
});

#3

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


#4

I haven’t heard, how will things change?


#5

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.


#6

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


#7

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.


#8

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