Mandrill忽略换行符(\ n) [英] Mandrill ignores line breaks (\n)

查看:91
本文介绍了Mandrill忽略换行符(\ n)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 send-template 方法和 Lutung Mandrill Java API 实现,当模板变量包含形式为\n的换行符时,在生成的电子邮件中被完全忽略或剥离.包含\n字符的String保持不变,直到执行GET send-template方法.因此,我想在Mandrill服务器上进行了String分析和转换,可以删除特殊字符.

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.

如何在Mandrill电子邮件上重新换行?

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

推荐答案

在我的情况下,我将手把用于Mandrill模板,并且已通过将HTML发送到模板<br/>而不是\n来解决此问题,方法是替换了在我的带有<br/>的字符串中,例如:.Description.Replace("\n", "<br/>");

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/>");

然后在mandrill模板上,将变量放入{{{variable}}}而不是{{variable}}

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转义

Handlebars HTML返回的值由 {{expression}}.如果您不希望车把转义一个值,请使用 三重存储","{{{.

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

在您的模板中:

<div> {{{html_tag_content}}} </div>在您的API请求中:

<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"   } ]

结果:

此示例
全部有关
车把的神奇世界

This example
is all about
the magical world of handlebars

这篇关于Mandrill忽略换行符(\ n)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆