30

Suppose I want to build a dynamic table. How do I run each inside each. If the only varible that represents current item is this.

   {{#each by_width}}
       {{#each by_height}}
          {{this}} // how do refer to this from the outer loop?
       {{/each}}
   {{/each}}
0

2 Answers 2

74

You can use ../ to access the parent in a Handlebars template:

{{#each by_width}}
    {{#each by_height}}
       w: {{../this}}
       h: {{this}}
    {{/each}}
{{/each}}

That of course assumes that by_height is inside each element of by_width, if they're both at the top level then you'd need another ../:

{{#each by_width}}
    {{#each ../by_height}}
       w: {{../this}}
       h: {{this}}
    {{/each}}
{{/each}}

Demo: http://jsfiddle.net/ambiguous/PNTXw/

Sign up to request clarification or add additional context in comments.

1 Comment

And how do you get {{@index}} of {{../this}} ?
0

Don't write {{../this}} but {{..this}}.

2 Comments

are you sure {{..this}} working withobject keys in loop
When I wrote that, yes I was sure. But, I haven't been doing meteor for a while.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.