I am stuck in my custom code.

I want to pass a custom variable from email template to pthml file.

Edit file


in this function :

public function sendNewOrderEmail()

--- default code start ----
                'order'        => $this,
                'test'        => 'XXXXX',
                'billing'      => $this->getBillingAddress(),
                'payment_html' => $paymentBlockHtml
--- default code end ----

and then I put this code in New Order email template:

{{layout handle="sales_email_order_items" order=$order  test=$test}}

template file located here :


and I am trying to get test variable Here:


like this: $test = $this->getItem()->getTest()

but get success. Please let me know where am I wrong? or what to do need to access this variable in phtml file?

Thanks in advance!

  • What exactly is the "test variable" is it a customer attribute, product attribute, a block of test, etc?
    – kab8609
    Commented Dec 26, 2013 at 15:36
  • it's a merchant emails array Commented Dec 27, 2013 at 4:47

1 Answer 1


When passing a variable this way:

{{layout handle="sales_email_order_items" order=$order  test=$test}}

You make it available in the email/order/items.phtml template only.
You are able to get it there with: $this->getTest() or $this->getData('test').
To pass it further to the email/order/items/order/default.phtml edit the items.phtml file and add this


before calling

<?php echo $this->getItemHtml($_item) ?>

To make it shorter, replace:

<?php echo $this->getItemHtml($_item) ?>


<?php echo $this->getItemHtml($_item->setTest($this->getTest())) ?>
  • You save my time.... Genius :) Commented Apr 17, 2019 at 12:53

Your Answer

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

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