pass custom variable/parameter from email template to phtml file

Lalit Kaushik picture Lalit Kaushik · Dec 26, 2013 · Viewed 16.6k times · Source

I am stuck in my custom code.

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

Edit file

app/code/local/Mage/Sales/Model/Order.php

in this function :

public function sendNewOrderEmail()
  {

--- default code start ----
$mailer->setTemplateParams(array(
                '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 :

app/locale/en_US/template/email/sales/order_new.html

and I am trying to get test variable Here:

app/design/frontend/default/default/template/email/order/items/order/default.phtml

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

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

Answer

Renon Stewart picture Renon Stewart · Dec 26, 2013

To get variable in your email template

{{var test}}

Take a look @ Defining Transactional Variables