Search code examples
mandrill

Mandrill - Send HTML tags inside X-MC-MergeVars


I tried to send HTML tags inside X-MC-MergeVars for my Mandrill handlebar template, but doesn't seem to work.

PHP part:

[...]
$message->getHeaders()->addTextHeader("X-MC-MergeVars", json_encode(["foo" => "b<strong>a</strong>r"]));

Mandrill template part:

[...]
Here is my var {{foo}}

And the result

Here is my var b<strong>a</strong>r

Do you know if it's possible to Mandrill to translate HTML inside a string?

Thank you


Solution

  • The solution is pretty easy actually.
    You have to replace your double brace {{by triple brace {{{

    [...]
    Here is my var {{{foo}}}
    

    Mandrill API (HTML escaping)

    Handlebars HTML-escapes values returned by an {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", "{{{.