0

I have created a custom module to send custom email template.

But i want to send array value so need to use the loop i have tried in mail file but it doesn't work.

Any one have any idea how to send data in loop and used that in template.

1
0

Step 1: First you need to add a layout file in your module.

modulename/view/frontend/layout/yourxml.xml

<?xml version="1.0"?><page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Label" design_abstraction="custom"><body><block class="Magento\Framework\View\Element\Template" name="additional.product.info" template="Vendor_Module::email/filename.phtml"/></body></page>

Step 2: Create Phtml file in modulename/view/frontend/templates/email/filename.phtml

<?php $items = $block->getItems() ?><table class="email-items"><thead><tr><th class="item-info"><?= /* @escapeNotVerified */  __('Items'); ?></th><th class="item-qty"><?= /* @escapeNotVerified */  __('Qty'); ?></th><th class="item-price"><?= /* @escapeNotVerified */  __('Product Price'); ?></th></tr></thead><tbody><?php foreach ($items as $item): ?><tr><td><?= $item->getName() ?></td><td><?= $item->getSku() ?></td><td><?= $item->getPrice() ?></td></tr><?php endforeach; ?></tbody></table>

Step 3: In your email Template add the below code

{{layout handle="yourxml" items=$items area="frontend"}}

Your template variable items must be object and add the object/array in the email template variable

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.