I'm using Mandrill's own PHP library to preview and send templated emails. I've verified that sending works as expected by replacing the tags, but the template->render
method returns the (correct) template without replacing the tags. Searching turned up no relevant results, so I can only assume I'm doing something wrong. The only similar question I found was this, with no answer.
Documentation for the render method is here.
Below is the request and response.
Request
{
"template_name": "welcome",
"template_content": [
{
"name": "member_first_name",
"content": "James"
},
{
"name": "useLogo",
"content": true
}
],
"merge_vars": [
{
"name": "member_first_name",
"content": "James"
}
{
"name": "useLogo",
"content": true
}
],
"key": "blah"
}
Response:
{
"html": "<p>Dear {{member_first_name}},</p>" [etc]
Unless I'm misunderstanding the API docs, {{member_first_name}} should be replaced with the value I'm sending, just like it does for sending an email?
The two different calls to preview/send emails are as follows:
$mandrill->messages->sendTemplate($template_name, $template_content, $message, false);
$mandrill->templates->render($template_name, $template_content, $template_content, false);
where...
$template_content = array(
array(
'name' => 'member_first_name',
'content' => $memberFirstName
),
array([etc]
I attempted to implement this in Java for a different but related project, and came across the same issue. It turns out the Mandrill API does not support the use of Handlebar tags when rendering the template. I raised it as an issue with the Java library originally, but this applies to any library or direct API call.
More information, incl ticket number from Mandrill, can be found here:
https://github.com/rschreijer/lutung/issues/65