如何在模板电子邮件magento2中呈现数据类型html?


13

我在Magento 2中有电子邮件模板:email-template.html

{{template config_path="design/email/header_template"}}

{{trans "%body" body=$data.body}}

{{template config_path="design/email/footer_template"}} 

但是在变量中$data.body是代码html而不是文本:

$data.body = `
<table width="100%"> 
  <tr> 
     <td>Name: </td> <td>Join Xanka </td>
  </tr> 
  <tr> <td>Email: </td> <td>xanka@gmail.com</td> </tr>
  {{depend Test Send}} 
  <tr> <td>Subject: </td> <td>Test Send</td> </tr>
  {{/depend}} 
  <tr> <td>Message: </td> <td>we try send email use to test.</td> </tr>
</table>

因此,如何在发送发送电子邮件时呈现代码html。多谢!

这是print_r($this->_message->getBody());sendMessage()函数中使用借口代码时的结果:

在此处输入图片说明

Answers:


19

我更改{{trans "%body" body=$data.body}}{{trans "%body" body=$data.body|raw}}。它带来成功。



5

{{trans "%body" body=$data.body}}一起{{trans "%body" body=$data.body|raw}}

请记住要更改type="text"type="html"in email_templates.xml,否则您的邮件中将得到纯HTML。


非常感谢您的提示type =“ html”。我刚犯了一个冷酷的错误,它毁了大约半小时!
DRAJI,
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.