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.

asked Sep 16, 2021 at 10:47
1

1 Answer 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

answered Oct 7, 2021 at 11:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.