This is my observer file from where I am passing values to email_template.html

 foreach($items as $item) {
        $productIds[]= $item->getProductId();
        $productName[]= $item->getSku(); 
        $productPrice[] = $item->getPrice();
  //      $productQuantity[]= $item->getQty();

$transport = $this->_transportBuilder->setTemplateIdentifier('order_template')

How can I get the values of $productName and $productPrice in my email template.
I tried but not working


 <table class="email-items">
                        <th class="item-info">{{trans "Items"}}</th>
                        <th class="item-info">{{trans "Qty"}}</th>
                        <th class="item-info">{{trans "Sku"}}</th>
                        <td>{{var $productName.getSku()}}</td>
                        <td>{{var myvar8|raw}}</td>
                        <td>{{var $productPrice.getPrice()}}</td>


In email template html, we can add layout and pass the order object to this layout. For instance, in your layout:


{{layout handle="sales_custom_email_order_items" order=$order area="frontend"}}

Create your own layout:


<?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 Order Items List" design_abstraction="custom">

        <block class="Vendor\Module\Block\Order\Email\Items" name="items" template="email/items.phtml" cacheable="false">
             <!--Add more stuff here-->


And then, create Vendor\Module\Block\Order\Email\Items and email/items.phtml.

We should take a look some default files:

| improve this answer | |
  • hello @khoa i tried this but phtml file is not calling .. – Ramkishan Suthar Sep 21 '16 at 3:46
  • You should update your question with the block and phtml file. – Khoa TruongDinh Sep 21 '16 at 3:55
  • Error filtering template: Renderer list for block "items" is not defined. I am getting this error in mail. – Ramkishan Suthar Sep 21 '16 at 4:43
  • in core file of magento at endor/magento/module-sales/Block/Order/Email/Items.php there is not any single function ? what should i do ? – Ramkishan Suthar Sep 21 '16 at 4:45
  • i think phtml file is calling now ... – Ramkishan Suthar Sep 21 '16 at 4:45

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.