Magento – Magento 2: Date in email template

magento2PHP

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.

Best Answer

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);
Related Topic