Mandrill ignores line breaks (\ n)

Using the Lutung Mandrill Java API method and implementation , when a template variable contains form line breaks , they are completely ignored or stripped of generated emails. containing symbols remains intact until the method is executed . So my guess is that there is some analysis and transformation on the Mandrill servers that removes special characters. send-template

\n

String

\n

GET

GET

send-template

String

How can I resume line breaks on Mandrill emails again?

+5


source to share


2 answers


In my case I am using Handlebars for mandrill templates and I solved it by sending HTML to the template <br/>

instead of \n

replacing \n

in my line with <br/>

something like this:.Description.Replace("\n", "<br/>");

And then in 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 escape values ​​returned {{expression}}

. If you don't want Handlebars to escape the meaning, use the "triple stamp", "{{{.

In your template:

<div> {{{html_tag_content}}} </div>

In the API request:

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

      

Result:

This example is
all about the
magical world of rudders

+2


source


If you want to send more complex content, be it html or variables with dividing lines and not yet completely, you can render the template first and then send the message instead of directly using send-template

.

Extract the template by calling : templates.render

{
    "key": "example key",
    "template_name": "Example Template",
    "template_content": [
        {
            "name": "editable",
            "content": "<div>content to inject *|MERGE1|*</div>"
        }
    ],
    "merge_vars": [
        {
            "name": "merge1",
            "content": "merge1 content\n contains line breaks"
        }
    ]
}

      



Store the result in a variable rendered_content

.

Send a message using the generated template with : messages.send

{
    "message": {
        "html": rendered_content,
        ...
    ...
}

      

-1


source







All Articles