Question

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>

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

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?

Was it helpful?

Solution

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>

And this on the mailer:

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 
    }
  ....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top