10

I am trying to trigger a mail to customer after they place an order. This email will carry all the cross sell products of the products ordered.

I used the following links as reference:

send email using event observer

Advanced Transactional Email Templates

All is working well.

But now my doubt is, will I be able to use foreach loop inside the html file put inside the locale directory?

So that I could iterate and print all the product info in the mail template. Can anyone help?

21

I think that it is not possible to directly perform a foreach loop in emails, but what you could do is include a block that will do the loop in a regular template.

In you email add something like the following.

{{block type='core/template' area='frontend' template='email/template.phtml' items=$items}}

Then in your template add the following.

<?php foreach ($this->getItems() as $_item): ?>
    <p><?php echo $_item['name'] ?></p>
<?php endforeach; ?>

For more information I followed this blog

  • Ya I am actually was trying this. will accept this in 2 mins – Shathish Sep 27 '13 at 6:27
  • Do we have to add this block inside email template? And will it understand items=$items? As $items is php variable. – Akshay Taru Aug 21 '15 at 12:10
  • Hi, I tried above not working for me. Any suggestions – Akshay Taru Aug 23 '15 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.