0

I have custom email. I have passed HTML inside variable as follows.

But the issue is it is printing HTML instead of table

public function getTable()
    {

        $data = $this->getRequest()->getPostValue();
        // echo "<pre>";
        // print_r($data);
        // die();
        $size = substr_count($data['product_id'],',') + 1;
        $tot_arr = array();
        $value = array();
        $title = array();
        $first_spt = explode(',', $data['optiontitle']);
        $first_spt_val = explode(':', $data['optionvalue']);
        // for ($i=0; $i < 2; $i++) { 
        //     $tot_arr[$i]['title'] = explode('@@', $key);
        // }
        foreach ($first_spt as $key) {
            $title[] = explode('@@', $key);
        }


        foreach ($first_spt_val as $key => $val) {
            $searchForValue = ',';
            if( strpos($val, $searchForValue) !== false ) {
                $str_arr = preg_split ("/\,/", $val);  
                foreach ($str_arr as $str_arrkey) {
                    //echo $key;die;
                    $value[$key][] = explode('@@', $str_arrkey);
                }
            }else{
                $value[] = explode('@@', $val);
            }

        }


        $html = "<table>";

        $new  = array();
       for ($i=0; $i < $size; $i++) { 

            $html .= "<tr>";

            // $title[$i] = isset($title[$i]) ? $title[$i] : null;

            foreach ($title[$i] as $col) {
            $html .= "<th>" . $col . "</th>";
            }

            $html .= "</tr>";  
            $html .= "<tr>";
            // echo "<pre>";
            // print_r($value);
            // die();

            if ($this->contains_array($value[$i]) == 'true') {
                foreach ($value[$i] as $key) {
                    $html .= "<tr>";
                    $new = array_slice($key, 1, -1);
                    foreach ($new as $col) {
                        $html .= "<td>" . $col . "</td>";   
                    }
                    $html .= "</tr>";   
                }             
            }else{
                $new = array_slice($value[$i], 1, -1);
                foreach ($new as $col) {
                    $html .= "<td>" . $col . "</td>";   
                } 
            }


            $html .= "</tr>"; 

           //$value[$i]
       }

        $html .= "</table>";
         // echo "<pre>";
         //    print_r($html);
         //    die();
        return $html;
    }

For call this in templateoptions variable I have addded

$optionTitle = $this->getTable();

Output is like

enter image description here

I need to print table & not table tags

My type is HTML in email_templates.xml

Template HTML I have added

 <td colspan="2" valign="top" style="font-size:12px;padding:7px 9px 9px 9px;border:1px solid #EAEAEA;">
                                                {{var optionTitle}}<br></n>
                                                {{var optionValue}}
                                            </td>
3
  • please share your html file.
    – Msquare
    Apr 21, 2020 at 5:39
  • have you tried getChildHtml() ? Apr 21, 2020 at 5:40
  • I have added the file in ques
    – Arjun
    Apr 21, 2020 at 5:42

1 Answer 1

2

I got an answer to my own question, just posting it as it might help someone.

Need to add |raw

<td colspan="2" valign="top" style="font-size:12px;padding:7px 9px 9px 9px;border:1px solid #EAEAEA;">
   {{var optionTitle|raw}}<br></n>
   {{var optionValu|raw}}
</td>

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.