mandrill和嵌套合并变量

时间:2015-02-28 09:01:20

标签: ruby handlebars.js mandrill

我正在使用把手制作mandrill模板。并想知道如何使用嵌套合并变量?我正在使用ruby的mandrill-api gem。

global_merge_vars: [
  {name: 'receiver_name', content: receiver_name},
  {name: 'email_message.from_email', content: email_message.from_email},
  {name: 'email_message.from_phone', content: email_message.from_phone},
  {name: 'email_message.message_body', content: email_message.message_body},
],

在模板中:

<pre style="font-family: Arial, Helvetica, sans-serif; margin: 0">
    {{email_message.message_body}}
</pre>

但它不起作用。但是,对于&#34; receiver_name&#34;它有效。

1 个答案:

答案 0 :(得分:1)

{{email_message.xxx}}解析为空字符串,因为Handlebars尝试访问xxx的属性email_message,但它不存在,因为它没有嵌套。

目前,您似乎无法在global_merge_vars内创建嵌套变量(请参阅Mandrill doc)。

但我不确定这里是否需要嵌套变量。因此,您应该可以简单地将.替换为_,这样就可以了:

global_merge_vars: [
  {name: 'receiver_name', content: receiver_name},
  {name: 'email_message_from_email', content: email_message.from_email},
  {name: 'email_message_from_phone', content: email_message.from_phone},
  {name: 'email_message_message_body', content: email_message.message_body},
],

在你的模板中:

<pre style="font-family: Arial, Helvetica, sans-serif; margin: 0">
  {{email_message_message_body}}
</pre>