In this blog i’ll discuss about how to iterate(using foreach loop) the Collection in your custom email templates.
Let’s think situations like when you have to send an email which contains multiple customer addresses or product items, then you must need to iteration the collections in your custom email template.
Magento provide very simple architecture to implement this feature in your project:
Step 1: Add Below line in your email template
{{block type='core/template' area='frontend' template='yourmodule/email_template.phtml' addresses=$addresses}}
template:- here you have to specify your custom phtml file path which should be kept inside magento frontend part.
addresses:- it’s your Address collection which you want to iterate(using foreach loop) in your phtml file.
PHTML Path:- app/design/frontend/default/default/template/yourmodule
Now you can easily fetch your $addresses inside your phtml file like below:
<?php foreach ($this->getAddresses(); as $address): ?> <p><?php echo $address['name'] ?></p> <?php endforeach; ?>
Now It’s done you’re ready to send the email with multiple addresses.
I Hope this blog will help someone who needs above feature.
Thanks
1 comments