Active
Project:
Mandrill
Version:
7.x-2.0
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
2 Dec 2014 at 11:56 UTC
Updated:
2 Dec 2014 at 11:56 UTC
How to replace merge tags of Mandrill template in drupal. after some digging i found some solution its work fine for me. but i think its require more effort and carry the merge tag to 3 step.
First step is:-
//Implementation of hook_mail()
function mymodule_mail($key, &$message, $params){
if($key == "sendmandrillmail"){
$message['subject'] = 'This is a test mail subject';
$message['body'] = 'This is a test mail body';
//provide value to marge tag.
$message['global_merge_vars']=array(
array(
'name' => 'FNAME',
'content' => 'Dileep',
),
array(
'name' => 'LNAME',
'content' => 'Maurya',
)
);
}
}Second Step:-
/**
* implementation of hook_mandrill_mail_alter()
*/
function mymodule_mandrill_mail_alter(&$mandrill_params, $message) {
if(!empty($message['global_merge_vars'])){
$mandrill_params['function'] = 'mymodule_mandrill_template_sender';
$mandrill_params['args']['global_merge_vars']=$message['global_merge_vars'];
}
}
Third step :-
function mymodule_mandrill_template_sender($message, $template_id, $template_content,$global_merge_vars) {
if ($mailer = mandrill_get_api_object()) {
$message['global_merge_vars']=$global_merge_vars;
return $mailer->messages->sendTemplate($template_id, $template_content, $message);
}
return NULL;
}
Can i reduce this step?