0

I am trying to Get my html template to run as intended. I can't seem to figure out how to use if within handlebars.

I want to print a table with corresponding and nested data based on uniqe ID in from my json file:

Items: [

  { «Id»: «1234»,
   «Title»: «Ford»
  }

]

Subitems: [
  { «ItemId»: «1234»
   «Cartype»: «mustang»,
  },

  { «ItemId»: «1234»
    «Cartype»: «transit»
}


]

 <tr>
{each items}
 {if item.ID == subitems.itemid}
  «Add table row»
 {/if}
{/each}
</tr>

Based on the json i wanted to add 2 rows hete.

Does anyone have any tip on how to fix this?

I tried to add a helper but It doesn’t seem to do the trick

  • `Items` has only one element. If you are expecting two rows, I think you should call `{{#each Subitems}}`. Note that Handlebars uses two mustaches - as in `{{#each Subitems}}`, not `{#each Subitems}`. Finally, you won't be able to do a `==` comparison in a Handlebars template. You would need a helper for that. For example: https://stackoverflow.com/a/34252942/3397771 – 76484 Feb 05 '23 at 13:49

0 Answers0