This is my observer from where i am passing product name,prodcut price and product quantity in my custom email template file email_template.html .
$templateVars = array(
'store' => $this->storeManager->getStore(),
'order' => $order,
'items'=> $items,
'productName'=>$productName,
'productPrice'=>$productPrice,
'productQuantity'=>$productQuantity,
'payment_html' => $this->getPaymentHtml($order),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
);
$from = array('email' => "ramkishan.suthar@ranosys.com", 'name' => 'Ramkishan');
$this->inlineTranslation->suspend();
$to = array($customerEmail);
$transport = $this->_transportBuilder->setTemplateIdentifier('order_template')
->setTemplateOptions($templateOptions)
->setTemplateVars($templateVars)
->setFrom($from)
->addTo($to)
->getTransport();
$transport->sendMessage();
$this->inlineTranslation->resume();
In my email_template.html
<table class="email-items">
{{layout handle="email_product_list" items=$items area="frontend"}}
</table>
email_product_list.xml
product.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 */ __('Price'); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($_items as $_item): ?>
<tr>
<td><?php $_item->getName() ?></td>
<td><?php $_item->getSku() ?></td>
<td><?php $_item->getPrice() ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
what i am doing wrong ?
Best Answer
To loop the values in Email template
Step 1: you need to add one layout file in you module.
yourmodule/view/frontend/layout/email_product_list.xml
Step 2: Create Phtml file in yourmodule/view/frontend/templates/email/product.phtml
Then in your email template add the below code
{{layout handle="email_product_list" items=$items area="frontend"}}
Note : Your template variable
items
should be object