WordPress.org

Ready to get started?Download WordPress

Forums

wpMandrill
FYI: Example for using merge tags (1 post)

  1. redrocksrover2
    Member
    Posted 1 year ago #

    For anyone interested, here is a rudimentary example of one way to structure your call to wpMandrill in order to use merge tags in Mandrill/MailChimp templates.

    Let's say you have the merge tags *|firstname|*, *|lastname|*, and *|activationkey|* in your email template. Now you want to populate those tags with variables from WordPress. You need to pay attention to the structure of the $global_merge_vars and $merge_vars arrays. Here is an example with the merge vars set for one recipient. For multiple recipients, you'll have to set up a loop of some sort to pre-populate your global_merge_vars and merge_vars arrays with the values for each recipient :

    wpMandrill::mail(
       $to,
       $subject,
       $html = '',
       $headers = '',
       $attachments = '',
       $tags = array( 'mytag' ),
       $from_name,
       $template_name = 'mytemplate',
       $track_opens = TRUE,
       $track_clicks = TRUE,
       $url_strip_qs = TRUE,
       $merge = TRUE,
       $global_merge_vars = array(),
       $merge_vars = array( array(
          'rcpt' => $to,
          'vars' => array(
             array( 'name' => 'firstname', 'content' => $firstname ),
             array( 'name' => 'lastname', 'content' => $lastname ),
             array( 'name' => 'activationkey', 'content' => $activationkey )
          )
       ))
    );

    MC_Will: Great plugin. The documentation and comments in the source could be more clear regarding the structure of some of the expected arrays. It took looking at the API and the JSON string format to realize that the merge arrays, for example, aren't a simple one-dimensional array.

    http://wordpress.org/extend/plugins/wpmandrill/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by redrocksrover2
  • This topic is not a support question
  • WordPress version: 3.5.1

Tags

No tags yet.