We have a module which sends emails to customers. To get the data in the email, we're passing it to an html
template which then calls a phtml
template to actually render the data, passing the data along with it.
The flow is as follows:
- In our email sending method (in the controller) we're passing a model (a data object) to the template as variable:
// ...more code...
$this->transportBuilder
->setTemplateIdentifier('quotation_email')
->setTemplateVars(['quotationRequest' => $quotationRequest])
// ...more code...
- From there, we have an
html
template which then adds header and footer blocks and calls the actualphtml
template via a layout handle:
<!--@subject {{trans "Your Quote Request"}} @-->
{{template config_path="design/email/header_template"}}
{{layout handle="quotation_email" quotationRequest=$quotationRequest area="frontend"}}
{{block type="cms/block" block_id="agb_email_english"}}
{{template config_path="design/email/footer_template"}}
- Finally, in the
phtml
email template we're retrieving the data object with$quotation = $block->getQuotationRequest();
to use it in the template.
Up until 2.4.3 this worked without any issues. Since upgrading to 2.4.4 the template does not work anymore - the quotationRequest
is null
in the phtml
template.
In the migration guide for custom email templates it says
As of Magento 2.3.4, custom email templates are only allowed to use scalar values for variable data. Direct calls to methods are no longer allowed.
This explains why the variable is null
and does not contain the object when trying to retrieve it in the phtml
template.
Now the question is, how do I properly pass the object from my controller to the phtml
template?