Hi friends, my previous article has been written about email sending feature in Magento, and you can read it here. But it seems that we have one more issue – how to display collections/arrays data in the email templates. We’ll try to shed the light on this below.

The first thing we should know – is the impossibility to use foreach/for/while in the template. So we should include a block with the template from a current theme inside the email template instead, just like we do for CMS pages. See below:

Code:
{{block type='core/template' area='frontend' template='atwix/email/template.phtml'}}
Note, that is a very handy feature, but how do we pass data into the phtml file? – It’s easy:

Code:
{{block type='core/template' area='frontend' template='atwix/email/template.phtml' items=$items}}
And if you don’t remember how to pass data into email template, it will be helpful to read our previous articles

So, in this case $items variable may be an array or collection, etc…
Then, you just need to sort out your data in phtml-file, see the following example:

PHP Code:
<?php foreach ($this->getItems() as $_item): ?>
    <p><?php echo $_item['name'?></p>
<?php endforeach; ?>
As a result, you will see a dependence – if you pass items=$items you can get data in a phtml file using $this->getItems() function.

View more threads in the same category: