Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mandrill ignores line breaks (\n)

Tags:

mandrill

Using the send-template method and the Lutung Mandrill Java API implementation, when a template variable contains line breaks of the form \n, they are totally ignored or stripped on generated emails. The Strings containing \n characters are kept untouched untill the GET send-template method is executed. So I guess there is some String analysis and conversion on Mandrill servers which removes special characters.

How can I make work again line breaks on Mandrill emails?

like image 469
AxeEffect Avatar asked Oct 20 '22 13:10

AxeEffect


1 Answers

In my case I am using Handlebars for mandrill templates and I have solved this by sending HTML to the template <br/> instead of \n by replacing \n in my string with <br/> something like: .Description.Replace("\n", "<br/>");

And then on the mandrill template I put the variable inside {{{ variable }}} instead of {{ variable }}

http://blog.mandrill.com/handlebars-for-templates-and-dynamic-content.html

HTML escaping

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

In your template:

<div> {{{html_tag_content}}} </div> In your API request:

   "global_merge_vars": [   {
      "name": "html_tag_content",
      "content": "This example<br>is all about<br>the magical world of handlebars"   } ]

The result:

This example
is all about
the magical world of handlebars

like image 176
Amr Elgarhy Avatar answered Oct 22 '22 19:10

Amr Elgarhy