6

I use the Mandrill API to send my transactional Mails via PHP.

Now I'm running in the problem, that when I try to loop through multiple vars only the last one is shown.

this is my variable for global_merge_vars

array(
        array(
            'name' => 'products',
            'content' => array(
                array(
                    "name" => "Product 1",
                    "price" => "65€"
                ),
                array(
                    "name" => "Product 2",
                    "price" => "65€"
                ),
                array(
                    "name" => "Product 3",
                    "price" => "65€"
                )
            )               
        )
    );

My issue is glued to the products part with the array as content.

So if i try the following:

{{#each products}}
  {{name}} - {{price}}<br>
{{/each}}

I get

Product 1 - 65€
Product 2 - 65€
Product 3 - 65€

So far so good...

but if I try to wrap the whole thing in a table, I always just get the last array element shown...

<table>
  {{#each products}}
    <tr>
      <td>{{name}} - {{price}}</td>
    </tr>
    {{/each}}
</table>

results in:

Product 3 - 65€

Actually, I think, it's just a stupid mistake on my side, but right now, I have no idea what is the problem!

So thank you all in advance for your help :)

___________________UPDATE________________________

i also found out, that it works if i put the whole table in the loop, like the following:

{{#each products}}
  <table>
    <tr>
      <td>{{name}} - {{price}}</td>
    </tr>
  </table>
{{/each}}

but thats not really what i want as stated before :)

FalcoB
  • 1,333
  • 10
  • 25
  • 1
    @kjpc-tech check my answer if you still have a problem – Layon Ferreira Oct 19 '21 at 16:25