1

I am trying to put a transactional email in SendWithUs using jinja. My data contains a double nest variable.

> {   "bookingList": [
>     {
>       "attendees": [
>         {
>           "age": "8",
>           "name": "Tommy"
>         },
>         {
>           "age": "9",
>           "name": "Mila"
>         }
>       ],
>       "classStartTime": "2020-01-30T17:00:00.000Z",
>       "classTitle": "Test class",
>       "count": "2",
>       "price": "10"
>     },
>     {
>       "attendees": [
>         {
>           "age": "8",
>           "name": "Tommy"
>         },
>         {
>           "age": "9",
>           "name": "Mila"
>         }
>       ],
>       "classStartTime": "2020-01-30T17:00:00.000Z",
>       "classTitle": "Test class 2",
>       "count": "2",
>       "price": "10"
>     }   ],   "customerInfo": {
>     "email": "test@test.com",
>     "firstName": "test"   },   "orderInfo": {
>     "orderId": "64d02680-364d-11ea-981c-42010a2ad1c1",
>     "subtotalPaid": "32.09",
>     "taxPaid": "3.94",
>     "totalPaid": "36.03"   },   "subject": "Test 123" }

I am trying to get the data to show

These are your enrollment details:
{{bookingList.attendees.name}} is enrolled in {{bookingList.classTitle}} on {{bookingList.classStartTime}}

It is showing the classTitle and classStartTime correctly, but is pulling in the word 'name' instead fo the actual name.

How do you treat double nested variables?

B25Dec
  • 2,301
  • 5
  • 31
  • 54
JaylovesSQL
  • 33
  • 2
  • 5

1 Answers1

1

Basically what you want to do is a have for loop within a for loop. Here's a simplified example of what I think you're trying to do:

<html>
  <head></head>
  <body>
    These are your enrollment details: <br>
    {% for item in bookingList %}
      {% for attendee in item.attendees  %}
      {{attendee.name}} is enrolled in {{item.classTitle}} on {{item.classStartTime}} <br>
      {% endfor %}
    {% endfor %}
  </body>
</html>

Which renders as:

These are your enrollment details:
Tommy is enrolled in Test class on 2020-01-30T17:00:00.000Z
Mila is enrolled in Test class on 2020-01-30T17:00:00.000Z
Tommy is enrolled in Test class 2 on 2020-01-30T17:00:00.000Z
Mila is enrolled in Test class 2 on 2020-01-30T17:00:00.000Z
Dylan Moore
  • 530
  • 2
  • 8