Magento – Get custom HTML variable from email template

emailmagento-1.9template

I had this issue:

I have created a custom mail where I send a list of products.
For this in my controller i concatenated a variable like this:

foreach (.....){
    $orderItems .= "<tr>
      <td>
        <p>" . $productSku . "</p>
        <p>" .  $differanceQty . "</p>                         
      </td>
    </tr>";
}

When I tried to send this variable from my controller to the email template in my email I received the HTML code instead of only the value.
So my custom email doesn't interpret my variable in the right way.

So I started looking for an answer and I didn't find anything related to this issue so that's why I posted this, maybe this will help someone.

the solution is to use the variable like this in the mail :

{{var order}} insead of {{htmlescape var=$order}}

Best Answer

The reason why you can get the variable {{var order}} is because you have the possibility to setTemplateParams() where you specify an array with params. This can be seen in Mage_Core_Model_Email_Template_Mailer:147

public function setTemplateParams(array $templateParams)
{
    return $this->setData('template_params', $templateParams);
}

Then the class core/email_template sends the array of params via its method sendTransactional() and that is why the custom variables are working for you.

Related Topic