MailChimp API - dynamic content - mc:repeatable + mc:edit
Asked Answered
R

1

1

My email template has some intro text followed by a repeatable block [a picture + a button].

I would like to repeat this block some X times and each time have picture link and button link updated with new links.

Currently I am using this payload to edit one block, and it is working as intended. I have used this SO answer as a guideline.

 var data = {
             'template': {
                          'id': template_id,
                          'sections': {
                                        'editbutton': '<a class="mcnButton " title="Get Profile" href="' + button1 + '" target="_blank" style="font-weight: bold;letter-spacing: normal;line-height: 100%;text-align: center;text-decoration: none;color: #FFFFFF;">GET DATA</a>',
                                        'editimage': '<img alt="" src="' + image1 + '" width="564" style="max-width:564px; padding-bottom: 0; display: inline !important; vertical-align: bottom;" class="mcnImage">'
                                      }
                         }
             };

What I am struggling is repeating this block and updating image and button link.

I am working in Google Apps Script but I guess the problem is independence of language.

Any help would be appreciated. Thanks.

Rabia answered 9/12, 2018 at 12:58 Comment(0)
R
3

I do not think you need to use the mc:repeatable or the mc:variant at all. Use the single mc:edit="editbutton_and_editimage_items_list" MailChimp tag. Put there dynamically generated HTML <ul><li> list with your actual data via sections part of the payload you sent to the API.

E.g. your sections.editbutton_and_editimage_items_list JSON item in your var data = {..} object above would look like:

   <ul>
        <li>
            <a class="mcnButton " href="' + button1 + '" style="...">GET DATA</a></li>
            <img alt="" src="' + image1 + '" width="564" style="..." class="mcnImage">
        </li>
        <!-- Repeat the LI with different data as needed --!>
   </ul>

After you successfully set the template content of your yet-not-sent campaign with the data above, use the API to send the campaign.

Runyon answered 9/12, 2018 at 18:20 Comment(2)
Thanks for your help. I ended up doing exactly this. I added mc:edit on top of the image + button. and updated it using sections as you have mentioned.Rabia
@urwaCFC, glad to hear this :) What I sometimes do is only using the MailChimp lists as a convenient storage for email database with no-brainer double opt-in and use my own local custom email template to generate whatever email I need. To make a campaign send out, I get the list of subscribers from MC, generate the email markup on my server and send out it via, say, PHPMailer. I also can use the SendGrid transaction emails API instead of PHPMailer still keeping lists at MailChimp. The latter allows for campaign statistics, yet it is much cheaper then MC's Mandrill.Runyon

© 2022 - 2024 — McMap. All rights reserved.