14

I have email template in Magento 2: email-template.html

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

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

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

But in variable $data.body is code html not text:

$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>

So how to render code html when send send email. Many thank!

This is result when excuse code print_r($this->_message->getBody()); in sendMessage() function:

enter image description here

20

I change {{trans "%body" body=$data.body}} to {{trans "%body" body=$data.body|raw}}. it render success.

| improve this answer | |
10

Use |raw with your param variable.

example: {{var data|raw}}

where data is a param variable that passed to a template and contains a value which is HTML code. data=<html code>

| improve this answer | |
6

Along with {{trans "%body" body=$data.body}} to {{trans "%body" body=$data.body|raw}}.

Do remember to change type="text" to type="html" in email_templates.xml, otherwise you'll get plain HTML in your mails.

| improve this answer | |
  • Thank you so much for the tip type="html". I just made a chilly mistake, It ruins around half an hour! – DRAJI Feb 22 '19 at 19:06

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.