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 :)
This is probably too late for OP but after spending a few hours trying to understand this, I came across the solution on a GitHub thread. Basically you put your handlebar tags on a HTML comment like this:
<table>
<!-- {{#each products}} -->
<tr>
<td>{{name}} - {{price}}</td>
</tr>
<!-- {{/each}} -->
</table>
credits: gurpreetatwal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With