Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mandrill template variables not substituting

Having issue with template variables not substituting when sending an email. I have a simple template:

<div class="entry"> Your name is {{firstName}} </div>

And my python code to send an email:

client = mandrill.Mandrill(apikey=api_key)

my_merge_vars = [{'content': 'Dexter', 'name': 'firstName'}]
message = {'from_email': '[email protected]',
       'to': [{'email': '[email protected]',
               'name': 'Deborah',
               'type': 'to'}
       ],
       'subject': 'example subject',
       'global_merge_vars': my_merge_vars

}
result = client.messages.send_template(template_name='test-template',
                          template_content=[],
                          message=message)

The email sends, however I get: Your name is {{firstName}}

like image 360
mingxiao Avatar asked Jun 11 '15 17:06

mingxiao


People also ask

How do I add a variable to a template?

Choose Template > New Variable from the editor toolbar (or choose an existing variable to add it to the page) Enter a name for the variable. Press Enter (by default this will create a single-line text input field)

How do I add a template to Mandrill?

Use the drag and drop template editor to make the desired template, then copy the code and paste it into the Mandrill template editor. Or connect your Mandrill and Mailchimp accounts and let Mandrill copy your templates over for you.

What are variables in templates?

Template variables help you use data from one part of a template in another part of the template. Use template variables to perform tasks such as respond to user input or finely tune your application's forms. A template variable can refer to the following: a DOM element within a template.

How do I create an email template in Mandrill?

The simplest way to create templates to send through Mandrill, is to use the Mailchimp drag and drop templates, then when your template is created, click "Save and Exit". Go to the templates list, and then in the drop down to the right of the templates menu, select "Send to Mandrill".


1 Answers

Make sure you specify that the merge type is handlebars. You can either do it in your account settings (Settings > Sending Defaults > Merge Language) or in your API call via the 'merge_language' parameter.

like image 114
Reza Avatar answered Oct 04 '22 15:10

Reza