Working with templates via API

1,195 views
Skip to first unread message

Igor

unread,
Aug 3, 2011, 9:29:35 AM8/3/11
to MailChimp API Discuss
Hi,

Maybe I got something wrong but the how can I feed template with
custom data via api call (create campaign). So for example I have an
email template where I want to put today's day name before creating
campaign. Can I do that? I don't want to use merge vars from list
because every day a part of newsletter content will be changed. So the
basic question is there any way to push data into template before
creating campaign? (Without creating a new template for each campaign)

Thanks.

jesse

unread,
Aug 3, 2011, 3:03:03 PM8/3/11
to MailChimp API Discuss
Sure, update the template with templateUpdate() before using it:

http://apidocs.mailchimp.com/api/rtfm/templateupdate.func.php


jesse

Igor

unread,
Aug 4, 2011, 3:40:18 AM8/4/11
to MailChimp API Discuss
Is there any chance to fill in repeatable sections? So for example I
have list of products and I want to have product section only once in
template and then iterate over them and copy section of template. I
have read previous discussion on this topics and googled but I still
don't understand whether it is possible via an API.

Thanks!

jesse

unread,
Aug 4, 2011, 7:39:14 AM8/4/11
to MailChimp API Discuss

Igor

unread,
Aug 4, 2011, 7:54:23 AM8/4/11
to MailChimp API Discuss
I saw this thread but this is not the same. In the thread the sections
are already defined and present in template the thing I want to do is
the basic feature of any template engine I want to have something like
that:

I will express it in ERB and then in mc template (how do I think it
could work)

<ul>
<% @products.each do |product| %>
<li><%= product.name %></li>
<% end %>
</ul>

=>

<ul mc:repeatable>
<li mc:edit="product_name"></li>
</ul>

P.S: Maybe I'm getting the whole concept wrong? Because it seems that
iteration over collection is basic operation. The thing I want to
achieve is to let customer setup template for a daily newsletter once
and then send it every day with different list of products (with
variable length).

Thanks!


On Aug 4, 2:39 pm, jesse <je...@mailchimp.com> wrote:
> You can play around with what these guys worked out:
>
> http://groups.google.com/group/mailchimp-api-discuss/browse_thread/th...

jesse

unread,
Aug 4, 2011, 7:59:23 AM8/4/11
to MailChimp API Discuss
It is the same - the way I linked is how you can add repeatable
content to a campaign. And yes, you should also name all of your
repeatable sections for clarity.

Maybe you just don't understand the difference between a template and
a campaign?

http://kb.mailchimp.com/article/whats-the-difference-between-a-template-and-a-campaign/


jesse

Igor

unread,
Aug 4, 2011, 9:03:34 AM8/4/11
to MailChimp API Discuss
Yes I understand the difference between campaigns and templates.

And yes I've finally was able to get things working (almost):

So my template looks like this:
<html>
<body>
<ul mc:repeatable="product">
<li mc:edit="product_name">product_name</li>
</ul>
</body>
</html>

And after playing with firebug in template editor and using provided
thread I've finally understood the cryptic naming pattern. So for the
following template to fill it with data I need to pass this hash

{ # content for campaignCreate method
"html_repeat_1:0:product_name" => "PRODUCT TITLE 1",
"html_repeat_1:1:product_name" => "PRODUCT TITLE 2",
"html_repeat_1:2:product_name" => "PRODUCT TITLE 3"
}

But now I have problem with naming - repeat_1 doesn't look like a good
name so I've decided to name it "product" but it still named repeat_1
and when I do templateInfo(templateId)["source"] call the
mc:repeatable name is removed so it looks like this

<ul mc:repeatable>
<li mc:edit="product_name"></li>
</ul>

The problem with that is that if I add another repeatable section
before this section the repeat_N numbering will change and all things
will break up. And furthermore it seems that your internal things are
breaking in this case. Maybe this is kind of bug?

Steps:
1. I have one repeatable in a template
2. I go to My Templates -> Select template -> Edit
3. I add item
4. I save it
5. I go to My Template -> Select template -> Code
6. I add one more repeatable section before existing one
7. When I save and go again to template edit page I'll have first
repeatable section repeated twice instead of second one

Screencast:
http://screencast.com/t/OOKdvdfTgh

Thanks!



On Aug 4, 2:59 pm, jesse <je...@mailchimp.com> wrote:
> It is the same - the way I linked is how you can add repeatable
> content to a campaign. And yes, you should also name all of your
> repeatable sections for clarity.
>
> Maybe you just don't understand the difference between a template and
> a campaign?
>
> http://kb.mailchimp.com/article/whats-the-difference-between-a-templa...
Reply all
Reply to author
Forward
0 new messages