15

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>[email protected]</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

3 Answers 3

23

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

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

1
  • thank you its very useful Commented Oct 24, 2019 at 9:58
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.

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

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.