How To Render A Widget In An Email Template


To include a widget in an email template use the shortcode [widget=Name of Widget].


Another option is to have the results of a widget sent to a variable. This option will apply if you have a custom widget and you want more control over what data will be used in the e-mail template.

STEP 1: Create the widget variable

$widget_var = widget("Name of Widget");


Another way


echo widget("Name of Widget);

$widget_var = ob_get_contents();



STEP 2:  Include this variable in the email one of the following ways.


Pass the variable in the $w variable. Take $var and save it as $w['widget_var'] for instance.


Then reference this inside of your email template as %%%widget_var%%%

STEP 3: Use the code to pass this newly created variable into the email template and send the email

$w['widget_var'] = $widget_var;

$email = prepareEmail('templae-name-goes-here', $w);  /// Email Template to Send

sendEmailTemplate($email['sender'], $user['email'], $email['subject'], $email['html'], $email['text'], $email['priority'], $w);   //// Send Email



You can also pass the value directly into the email, skipping the email template. To do this, you can declare each of the parameters separately. 

///This must include the sender name and email address. Name <[email protected]>

$email['sender'] = $w['website_name']." <".$w['website_email'].">";

/// This must be a valid email

$user_email] = "";

/// You must input a subject

$email['subject'] = ""Subject";

/// You must input a body in html

$email['html'] = "<strong>Your html code</strong>".$widget_var."with the variable from the widget included"; 

/// Email Text, If this is blank the system will strip the tags and send a text version
$email['text'] = "Text version of your email";

///Email Priority, can be left blank or input a number
$email['priority'] = "2";

 /// This function will send the email

sendEmailTemplate($email['sender'], $user['email'], $email['subject'], $email['html'], $email['text'], $email['priority'], $w);  

* Note both the subject and a body are required to send an email this way.