Verse of the Day – Part 3: MailChimp templates

Beside getting OAuth 2 setup for Google Apps, the hardest part of this was to come up with a simple way to create and send MailChimp campaigns with a similar layout and look, but with some custom content. My choices seem to be to between:

1. Create the full HTML5 content from scratch, taking care to include the required Mailchimp tags like *|UNSUB|* or *|HTML:REWARDS|*

2. Use the mailchimp.campaigns and mailchimp.campaigns.template_content from the Mailchimp API to take the template from the campaign and inject content in just the places I want it.

So that I could allow users the chance to continue using the Mailchimp template editor and then just provide search-n-replace snippets, I opted for #2. If I wanted to have radically different content style each time or I had content providers that where more savvy with HTML5 skills and tools, #1 would work, but that is not my world.

First, I created a place-holder campaign there I would layout the style and the bits to be replaced with content. All future campaigns would be replicated from this one then altered using the campaign settings and altering the campaign content itself. Settings are easy with code like:

The content is a bit messier. I get the template as a big data structure with mailchimp.campaigns.template_content(campaign_id), search through it for my search-n-replace “tags” then  use the campaigns.update method to inject it back into the content.

While this works for the simple temple I use, it tends to fall apart for templates with nested sections like Mailchimp allows.

Because this is for a “verse of the day”, there is also code in the script to grab HTML formatted verses from ESV api

10. August 2015 by ChrisJ
Categories: Coding | Leave a comment

Leave a Reply

Required fields are marked *