01 / Data-driven content
Why build 24 emails when you can build one?
Betty Crocker × Hallmark Channel — 24 Days of Cookies
Developed a reusable, data-driven email template for the 24 Days of Cookies campaign using Salesforce Marketing Cloud and AMPscript. Rather than developing 24 individual emails, a single template dynamically assembled each day's content from a centralized data extension.
The marketing team could prepare campaign content in advance, while date-based logic determined which content to display. This separated content management from development, reduced repetitive production work and maintained a consistent responsive experience throughout the campaign.
THE ARCHITECTURE
Build it once. Populate it 24 times.
Instead of hardcoding a new email every day, I separated the content from the template. The marketing team could populate all 24 days of campaign content in advance, and the email would determine which content to display.
- Data
Campaign Data Extension
- Daily campaign content
- Recipe information
- Movie pairings
- Images, copy and links
- Logic
AMPscript
- Date-based content selection
- Data retrieval
- Fallback handling
- Dynamic variable assignment
- Template
Reusable Email Template
- Dynamic content placement
- Responsive layout
- Consistent presentation
- Output
Daily Email Experiences
- Day 01
- Day 02
- …
- Day 24
THE IMPLEMENTATION
Here's where it gets interesting.
The finished email is only half the story. Here's a look at some of the logic working behind the scenes.
Turn the current date into a lookup key
The template formats the current date and appends a midnight time suffix to match the daily date values in the data extension.
Shortened from the campaign source. The data extension name has been anonymized.
set @table = "CampaignContent"
set @currentTime = formatDate(Now(),"MM/dd/YYY")
set @modCurrentTime = concat(@currentTime, " 12:00:00 AM")
set @lookupValue = @modCurrentTime
set @tableLookUpColumn = "date"Fall back when the date has no match
The first lookup checks for a row matching the date. If the result is empty, the template switches to a predefined date key so later lookups use the fallback content.
Shortened from the campaign source. The fallback date is redacted and diagnostic lines are omitted.
set @date = Lookup(@table,"date", @tableLookUpColumn, @lookupValue)
IF Empty(@date) THEN
set @lookupValue = "[fallback date]"
set @day = Lookup(@table, "day", @tableLookUpColumn, @lookupValue)
set @moddate = formatDate(@lookupValue,"MM_dd_YYY")
ELSE
set @day = Lookup(@table, "day", @tableLookUpColumn, @lookupValue)
set @moddate = formatDate(@date,"MM_dd_YYY")
ENDIFBuild a tracked link from editorial copy
AMPscript splits the marked-up tip into surrounding copy, link text, and a destination. It assembles an anchor with a tracking alias, then renders the resulting rich text in the email.
Shortened from the campaign source. The tracking alias was anonymized and the surrounding HTML was omitted.
/* modifying url*/
set @tipNew = ReplaceList(@tip_text, "|", "[", "]")
IF IndexOf(@tipNew, "|") > 0 THEN
SET @rs = BuildRowsetFromString(@tipNew,'|')
SET @part1 = trim(Field(Row(@rs,1),1))
SET @part2 = trim(Field(Row(@rs,2),1))
SET @part3 = trim(Field(Row(@rs,3),1))
SET @part4 = Field(Row(@rs,4),1)
ENDIF
set @ModifiedTipWithURL = concat(@part1, ' <a href="httpgetwrap|', @part3, '" alias="Tip_Link" style="color:#EB0000; text-decoration:underline;">',@part2,'</a>',@part4)
%%=TreatAsContent(@ModifiedTipWithURL)=%%Pair fluid columns with an Outlook table
The Bake and Watch columns are fluid inline blocks capped at 300 pixels each, so they can wrap when there is too little room side by side. Conditional comments give Outlook and IE a fixed-width presentation table with two 300-pixel cells.
Shortened and reformatted from the campaign source. Column contents, including image URLs and asset IDs, were omitted.
<td class="two-column" dir="ltr" style="padding: 0;Margin:0 0;text-align:center;font-size:0;">
<!--[if (gte mso 9)|(IE)]>
<table role="presentation" width="600" style="width:600px;border-spacing:0;" cellpadding="0" cellspacing="0">
<tr>
<td width="300" valign="middle" style="width:300px;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;">
<![endif]-->
<div class="column" style="width:100%;max-width:300px;display:inline-block;vertical-align:middle;" valign="middle">
<!-- Bake column content omitted -->
</div>
<!--[if (gte mso 9)|(IE)]>
</td><td width="300" valign="middle" style="width:300px;padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;">
<![endif]-->
<div class="column" style="width:100%;max-width:300px;display:inline-block;vertical-align:middle;" valign="middle">
<!-- Watch column content omitted -->
</div>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
