2

I am having a custom module in which I created a custom email template where I am displaying the details of some the items and it's cost.

I am getting the details like,

//Details table rows as string
$dataDetails .= '<tr><td align="left" width="325"  style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;"><strong>' . $item['name'] . $this->getCustomOptionText($item) . '<br>sku: </strong>' . $item['sku']
 . '</td><td align="right" width="325"  style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;">' . $formatedPrice
 . '</td><td align="right" width="325"  style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;">' . $item['qty']
 . '</td><td align="right" width="325"  style="font-size:13px; padding:5px 9px 6px 9px; line-height:1em;">' . $rowTotal . '</td></tr>';
    }

    //detail totals as a table in string
    $detail_footer = '<table>';

$detail_footer .= '<tr><td align="right" width="975" style="font-size:13px;padding:5px 9px 6px 9px; line-height:1em;" >SubTotal : </td><td>&nbsp;</td><td align="right" width="325" style="font-size:13px;padding:5px 9px 6px 9px; line-height:1em;" >' . $formattedsubTotal . '</td></tr>';

    //Parametes the template email variable to send
    $params = array(
        'customer' => $customer,
        'shippingTitle' => $shippingTitle,
        'shippingAmount' => $shippingAmount,
        'grandTotal' => $grandTotal,
        'website' => $websiteName,
        'dataDetails' => $quoteDetails,
        'detail_footer' => $quote_footer,

    );

I am sending the email below as,

            $postObject = new \Magento\Framework\DataObject();
        $postObject->setData($params);

    $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

    try {
        $transport = $this->_transportBuilder
                ->setTemplateIdentifier('details_email_template')
                ->setTemplateOptions(
                        [
                            'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
                            'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
                        ]
                )
                ->setTemplateVars(['data' => $postObject])
                ->setFrom($this->scopeConfig->getValue(self::XML_PATH_EMAIL_SENDER, $storeScope))
                ->addTo($customerEmail, $customer)
                ->getTransport();

        $transport->sendMessage();
        $this->inlineTranslation->resume();
    } catch (\Exception $e) {
        $this->messageManager->addError(__('Sorry, we can\'t send the email right now.' . $e->getMessage()));
    }

In my email template, I am calling the data_datils as,

<tbody>
    {{trans "%dataDetails" dataDetails=$data.dataDetails}}
</tbody>

Here, I am receiving the email properly, however, the data_details received in the email is including the email tags.

In the email received the contents are like,

<table><tr><td align="right" width="975" style="font-size:13px;padding:5px 9px 6px 9px; line-height:1em;" >SubTotal : </td><td>&nbsp;</td><td align="right" width="325" style="font-size:13px;padding:5px 9px 6px 9px; line-height:1em;" >$330.00</td></tr><tr><td align="right" width="975" style="font-size:13px;padding:5px 9px 6px 9px; line-height:1em;" >Discount : </td><td>&nbsp;</td><td align="right" width="325" style="font-size:13px;padding:5px 9px 6px 9px; line-height:1em;" >$0.00</td></tr><tr><td align="right" width="975" style="font-size:13px;padding:5px 9px 6px 9px; line-height:1em;" >Shipping & Delivery ( Flat Rate - Fixed ) : </td><td>&nbsp;</td><td align="right" width="325" style="font-size:13px;padding:5px 9px 6px 9px; line-height:1em;" >$20.00</td></tr><tr><td align="right" width="975" style="font-size:13px;padding:5px 9px 6px 9px; line-height:1em;" ><strong>GrandTotal : </strong></td><td>&nbsp;</td><td align="right" width="325" style="font-size:13px;padding:5px 9px 6px 9px; line-height:1em;" ><strong>$350.00</strong></td></tr></table> 

How can I exclude the HTML tags here and display only the values in the email? I have searched for it but could not find anything relevant.

I also tried using trim but this also couldn't give me the proper result,

trim(strip_tags($dataDetails))

Please, can anyone help?

3
  • I will look into this in a couple of hours Commented Nov 6, 2017 at 8:51
  • @SwAt.Be Hello, did u get time to look into the issue?
    – manini
    Commented Nov 6, 2017 at 12:57
  • I am sorry for the delay , i have a big deadline right now but i will get back to it tomorrow Commented Nov 7, 2017 at 4:04

1 Answer 1

2

I have figured out the solution by referring to the link below:

How to render data type html in template email magento2?

Thus instead of clipping the HTML tags out, we could directly render HTML content in the email template.

We can use '|raw' with the param variable something like,

{{trans "%dataDetails" dataDetails=$data.dataDetails|raw}}

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.