I am using Magneto 2.3.5-p1, I want to add some custom values in my New Order Transactional email template using block, for that, I have created a custom template from Marketing->Eamil Template and assigned that template from Store Configuration->Sales->Sales Email I have added below custom block in my email template

{{block class="Magento\\Framework\\View\\Element\\Template" order=$order name="sample_name" template= "VENDOR_MODULE::checkoutFieldsEmail.phtml" area = "frontend"}}

and in checkoutFieldsEmail.phtml have added below code even I removed all PHP code and put simple HTML for testing but not showing in email only default content is showing.

I have already added a new column in the sales_order table and the name of the column is Custom_column and added some JSON data.

    $helper = $this->helper('Vendor\Module\Data');
    $order = $block->getOrder();
    $_custom_value = $order->getCustom_column();
    $coafFields = json_decode($_custom_value,true);

1 Answer 1


I had done same by following below instruction.

  1. Create custom handler as "sales_email_order_content.xml" in app/code/vendor/package/view/frontend/layout/

  2. Add below code in "sales_email_order_content.xml"

         <block class="Magento\Framework\View\Element\Template" name="sales_email_custom_content" template="Vendor_Package::order_email.phtml"/>
  3. create order_email.phtml under path app/code/Vendor/Package/frontend/templates/ and add your logic. In this file you can get order object as we will pass this to layout handler

  4. Add below code in your custom Email template file

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

Hope it helps

  • still not working
    – ishaq
    Aug 11, 2020 at 20:01
  • okay can you add this code "{{layout handle="sales_email_order_content" order=$order area="frontend"}}" directly into new_order.html and check also which email html file is use. just change the content varify Aug 12, 2020 at 6:45
  • Thanks @Amitkumar it is showing content now in email, but how to access $order in the template file?
    – ishaq
    Aug 12, 2020 at 7:11
  • You can use "<?php $_order = $block->getOrder() ?>" and you can use assign this class "Magento\Sales\Block\Order\Email\Items" to work with order items. Aug 12, 2020 at 8:00
  • This is not working <?php $_order = $block->getOrder(); if($_order): ?> <h1>Some content</h1> <?php endif; ?>
    – ishaq
    Aug 12, 2020 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.