31

I've looked at this Mandrill knowledgebase article over and over and cannot see any obvious explanation of what the difference is between Global Merge Vars and Merge Vars, and when I should use global vs normal.

Both global_merge_vars and merge_vars are declared within the 'message' object (as shown here in the Mandrill API), so it's not like you're declaring global_merge_vars outside the message object and then including multiple merge_vars.

Also - is there any difference between how these are declared in the template itself or do they all just use *|MERGE_VAR_NAME|* format?

alexleonard
  • 1,314
  • 3
  • 21
  • 37
  • 7
    I'd also be intrigued to know why the 'template_content' array key is required but can be blank (I don't really know what it's meant for either) – alexleonard May 10 '13 at 09:17
  • 1
    Alex -- Did Kaitlin answer your question? If so please accept the answer or clarify what else you need help with. – Richard West Jun 07 '13 at 14:03
  • 3
    Woops! Sorry Richard - I got completely sucked into code for a while there. Kaitlin certainly put me on the right track although I did find the Mandrill API documentation a little confusing. I think it would be great if there were a few more examples on offer. – alexleonard Jun 08 '13 at 04:42

2 Answers2

58

The global_merge_vars parameter allows you to pass global values for a particular merge tag, to be applied for all recipients in that API call by default, while merge_vars allows you to specify per-recipient values based on the recipient email address (this is why the rcpt is declared for merge_vars). The content in the email or template doesn't vary - these API parameters are just distinct since they apply differently.

The template_content parameter is for editable regions in the template. More details here. Originally, Mandrill didn't support merge tags, and only supported editable regions in templates. For backwards-compatibility, template_content is still required when calling a template. It also helps to ensure that even if a template region isn't to be replaced, that's done explicitly by passing a blank array.

The Mandrill KB has quite a bit of info on various topics, and you can submit a support request there if you have questions specific to your account, or in general!

Kaitlin
  • 6,167
  • 32
  • 30
1

global_merge_vars: Give global or default values for merge tags by using the global_merge_vars parameter. These will be used in the case where a recipient doesn't have a recipient-specific value defined.

merge_vars: Use the merge_vars parameter to store recipient-specific values if sending to more than one recipient at a time.

Mritunjay Upadhyay
  • 1,004
  • 1
  • 15
  • 27