Reading list Switch to dark mode

    Magento Collection Iteration in Email Template

    Updated 26 March 2015

    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.

    Searching for an experienced
    Magento Company ?
    Find out More

    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

     

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    1 comments

  • Akshay Taru
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home