2

How can I add a custom variable to a email template in Magento 2 ?

I know that I can generate custom variables with HTML output but I want to output some PHP code.

I want to echo the date of the order in the email.

Thanks in advance!

Example of the email header

EDIT: Please note that I'm editing the email template in the admin section of the website. Not directly in the PHTML file.

  • Use {{trans "%orderDate" orderDate=$data.orderDate}} in ur mail template & pass orderDate variable from PHP – Ankit Shah Mar 1 '17 at 9:57
  • Thank you for your quick reply @AnkitShah Where do I set the function? – Jordy Mar 1 '17 at 9:59
0

Use {{trans "%orderDate" orderDate=$data.orderDate}} in ur mail template & in PHP

$emailTemplateVariables = array();
$emailTempVariables['orderDate'] = <order id from DB>;

$postObject = new \Magento\Framework\DataObject();
$postObject->setData($emailTempVariables);
  • Thank you @AnkitShah for your reply!, In which file do I need to put this in? Please note that I'm editing the email template in the admin section of the website. Not directly in the PHTML file. – Jordy Mar 1 '17 at 10:01

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.