0

I have a scenario where I want to use {{#each}} inside {{#each}}, I have two different arrays where I want to map one array with other with some if conditions. for ex:

array1 = [{
key1:value1,
key2:value2,
key2:value2
}]

array2 = [{
arrar2key1:value1,
arrar2key2:value2,
arrar2key3:value2
}]

And now I want to iterate this each like

{{#each array1}}
  {{key1}}
       {{#each array2}}
             {{#if xyz "123"}}
                {{arrar2key}}
             {{/if}}
       {{/each}}
{{/each}}

I tried this but didn't worked for me. I am using this handlebar with my node express to create pdf.

Akash
  • 9
  • 3
  • Does this answer your question? [Handlebars nested 'each' syntax - not iterating over each element](https://stackoverflow.com/questions/17197731/handlebars-nested-each-syntax-not-iterating-over-each-element) – AutMai Jul 23 '21 at 07:54
  • It is very unclear to me what you are trying to do. You have two arrays, but each just contains a single object. I don't understand the purpose of the arrays. – 76484 Jul 23 '21 at 23:03

1 Answers1

0

What you are trying to do, is to iterate through array2 of array1, in other words array1.array2. However, you don't want that to happen so you'll to change the code to the following to use the correct array2 variable:

{{#each array1}}
  {{key1}}
       {{#each ../array2}}
             {{#if xyz "123"}}
                {{arrar2key}}
             {{/if}}
       {{/each}}
{{/each}}
Gilles Heinesch
  • 2,889
  • 1
  • 22
  • 43