mailgun / mailgun.js

Javascript SDK for Mailgun
https://www.npmjs.com/package/mailgun.js
Apache License 2.0
519 stars 110 forks source link

Nested {{#each}} loop for templates do not display the right JSON object in Test Data #403

Open Jack2804 opened 8 months ago

Jack2804 commented 8 months ago

Hi. So i'm trying to create an email template for my webapp, and I encounter this issue where nested {{#each}} fails to generate a right JSON object for test data. I couldn't find the limitation anywhere in a doc. It is possible to do nested {{#each}} in Mailgun?

image

image

olexandr-mazepa commented 8 months ago

Hi @Jack2804 I did a check and nested loops seems working fine. At least the next template is working:

<table>
      {{#each all_services}}
        <tr>{{this.service_description}}</tr>
        {{#each this.service_items}}
          <td>{{this.aaa}}</td>
          <td>{{this.bbb}}</td>
        {{/each}}
      {{/each}}
</table>

I used the next data shape for it:

"all_services": [
  {
    "service_items": [
      {
        "aaa": "test_array_item_aaa",
        "bbb": "test_array_item_bbb"
      }
    ],
    "service_name": "service_name",
    "service_description": "service_description"
  }
]

The result is next: image

Based on provided screenshots you are missing service_items array to iterate through.

You can use the next doc to get familiar with Handlebars templating language. https://handlebarsjs.com/guide/#what-is-handlebars