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.

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

1 Answer 1

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);
1
  • 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
    Commented Mar 1, 2017 at 10:01

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.