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.
-
I have followed magento.stackexchange.com/questions/260101/… this link and successfully send the order data.Prits– Prits2021年09月23日 14:48:28 +00:00Commented Sep 23, 2021 at 14:48
1 Answer 1
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
Explore related questions
See similar questions with these tags.