Mandrill API模板 [英] Mandrill API Templating
本文介绍了Mandrill API模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是Mandrill的Ruby API Gem,并具有以下简单的测试模板:
I'm using Mandrill's Ruby API Gem and have the follow simple template for testing:
<html>
<body>
<h1 mc:edit="header">testastic</h1>
<hr/>
<br/><br/>
<div mc:edit="main_section"></div>
<hr/>
<div mc:edit="footer"></div>
</body>
</html>
按照Heroku指南的例子,我有以下Ruby代码:
Following the example on Heroku's guide I have the follow Ruby code:
require 'mandrill'
m = Mandrill::API.new
rendered = m.templates.render 'test-template', [{:header => 'some header text', :main_section => 'The main content block', :footer => '<h3>asdf</h3>'}]
mail(:to => "Jayson Lane <jayson@domain.com>", :subject => "Test Email") do |format|
format.html { rendered['html'] }
#format.text { render "test" }
end
这很好,电子邮件发送我的模板很好,但是,它不会替换模板mc:edit变量。我错过了什么吗?
This works great and the email sends my template just fine, however, it doesn't replace the template mc:edit variables. Am I missing something?
推荐答案
您需要为每个要替换的元素构造一个散列。例如,我有一个模板:
You need to construct a hash for each element you're trying to replace. For instance, I have this inside of a template:
<h3 mc:edit="plan_info_name"> </h3>
<span mc:edit="plan_info_description"> </span>
<span mc:edit="plan_info_benefits"> </span>
这个邮件:
mandrill.messages.send_template(template,[
{
:name => 'plan_info_name',
:content => extra[:membership_info].name
},
{
:name => 'plan_info_description',
:content => extra[:membership_info].long_description
},
{
:name => 'plan_info_benefits',
:content => benefits_list
}
....
这篇关于Mandrill API模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文