Mandrill API Templating

I am using the Mandrill Ruby API Gem and have the following 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>

Following the Heroku tutorial example, I have the following 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

This works fine and the email sent by my template is just fine, however it does not replace the mc template: edit variables. Did I miss something?

+5
source share
1 answer

You need to build a hash for each element that you are trying to replace. For example, I have this inside a template:

   <h3 mc:edit="plan_info_name"> </h3>
   <span mc:edit="plan_info_description"> </span>
   <span mc:edit="plan_info_benefits"> </span>

And this is in the mail program:

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 
    }
  ....
+9
source

All Articles