I have written an extension that builds a vars array, loads an email template and sends the html email.
However, the template is not being filled with the values of the variables and my output is EMPTY.
Here is the call to parse the variables:
//******************************************************
// Get the Template class;
//******************************************************
$this->EE->TMPL2 = new EE_Template();
//******************************************************
// Get the default email variables from our DB
//******************************************************
$email= $this->EE->email_model->get_email('customer-order-new');
//******************************************************
// Now load the email template from a file into the content
//******************************************************
$fl = PATH_THIRD.'_local/notifications/order-new.html';
if(file_exists($fl)){
// File helper
$this->EE->load->helper('file');
$email["content"] = read_file($fl);
} else {
return false;
}
//******************************************************
// Builds the $vars to be used to parse into the template
// class variable $this->vars is populated in this function
//******************************************************
$this->build_vars($data);
//******************************************************
// Parse the subject
//******************************************************
$subject = $this->EE->TMPL2->parse_variables($email["subject"], $this->vars);
//******************************************************
// Takes the $vars and parses the template with the values
//******************************************************
$output = $this->EE->TMPL2->parse_variables($email["content"], $this->vars);
//******************************************************
// Pass output to parse method by reference
//******************************************************
$this->EE->TMPL2->parse($output);The contents of the $email variable is in the attachment.
This is the contents of the vars array:
Array
(
[0] => Array
(
[site_name] => TNA
[site_url] => <a href="http://localhost:8040/">http://localhost:8040/</a>
[imagelink] => <a href="http://localhost:8040//media/images/logo_email.png">http://localhost:8040//media/images/logo_email.png</a>
[currency_marker] => $
[fullname] => Mr. Obama
[customer_info] => <span>
1600 Pennsylvania Avenue NW
Washington, DC 20500
US
T:202-456-1414</span>
[payment_info] => Credit Card<table> <tr> <td><br>Credit Card Type:</td> <td><br>VI</td> </tr> <tr> <td><br>Credit Card Number:</td> <td><br>XXXX-1111</td> </tr> <tr> <td><br>Payer Email:</td> <td>[email protected]<br></td> </tr></table>
[disclaimers] => Thank you for your order from the TNA.
<b>IMPORTANT INFORMATION REGARDING YOUR ORDER:</b> Verify the order by calling us at 202-456-1414.
<hr >
[grandtotal] => 419
[items] => Array
(
[0] => Array
(
[price] => 419
[sku] => 20140801OCA
[qty] => 1
[description] => <dl padding:0;"><strong>Obama Care Pkg</strong>
</dd>
</dt>
PRE-PAID Policy
)
)
)
)The $subject is parsed just fine, when it is echo’ed out it looks like this:
Thank you for your order - Order # 40000002I’m at a loss as to why the $output is empty. Am I doing something wrong here?