I was recently tasked with migrating a few themes from Mailchimp to Exact Target. While the overall experience I had working with ExactTarget was much less than stellar, I most disliked working with RSS feeds. The whole process of parsing an RSS feed seemed awkward.
So, in an effort to help others, and because I never want to figure out how to parse RSS for Exact Target again, here is how you can use RSS feeds within your Exact Target templates.
Create a Content Area
The method described to me by Exact Target’s support requires that the RSS be stored in a content area within the Exact Target interface. To do this, you will need to create an HTML content area and place the following within it:
[code]%%before;httpget;1"http://domain.com/rss"%%%5B/code%5D
This piece of code will fetch the contents of the RSS feed each time the content area is called.
For example, when we use ContentAreaByName("My Contentsrss_featured")
, the RSS is being fetched and stored at that time.
Parse the RSS Contents
Actually parsing the RSS feed and getting the desired output was a bit more difficult since Exact Target uses what I believe is a proprietary language named AMPscript.
Thankfully, the Exact Target support came through with a snippet of code that gave me a good head start. I took that snippet and built the following.
[code]
%%[
Var @xml, @titles, @title, @descs, @desc, @links, @link, @cnt, @dates, @date
Set @xml = ContentAreaByName("My Contentsrss_featured") /* This line specifies the content area from which the RSS content will be pulled for the email message. */
Set @titles = BuildRowsetFromXML(@xml,"//item/title",1)
Set @descs = BuildRowsetFromXML(@xml,"//item/description",1)
Set @links = BuildRowsetFromXML(@xml,"//item/link",1)
Set @dates = BuildRowsetFromXML(@xml, "//item/pubDate", 1)
If RowCount(@titles) > 5 THEN
SET @rows = 5
ELSE
SET @rows = RowCount(@titles)
ENDIF
IF @rows >= 1 THEN
for @cnt = 1 to @rows do
Set @title = Field(Row(@titles,@cnt),"Value")
Set @desc = Field(Row(@descs,@cnt), "Value")
Set @link = Field(Row(@links,@cnt), "Value")
Set @date = Format(DateParse(Field(Row(@dates,@cnt), "Value")),"MMM d, yyyy h:mm tt")
]%%
<div class="feed-item" style="background:#444;padding:10px 10px 0;margin-bottom:20px;border-left:4px solid #222;"><span style="color:#ffffff;font-size:16px;line-height:20px;margin-bottom:12px;">%%=v(@title)=%%</span>
<span style="color:#cccccc;font-size:12px;line-height:20px;margin-bottom:12px;">%%=v(@date)=%%</span>
<a style="text-decoration:underline;font-weight:normal;color:#336699 !important;" href="%%=RedirectTo(@link)=%%">More info…</a>
</div>
%%[
NEXT @cnt
ENDIF
]%%
[/code]
This snippet pulls out the Title, Description, Link, and Publication Date for each item in an RSS feed and puts it into what I consider to be an array.
The next is to then loop through these items, up to 5 rows worth, and get each value. Once we have these values stored in variables we can then place them in templates using the following syntax: %%=v(@varName)=%%
.
The biggest caveat in displaying the information was with inserting a link into the template. Notice that in the above example, %%=RedirectTo(@link)=%%
, there is an extra call to RedirectTo
. This has to do with the tracking system that Exact Target uses.
Questions?
This short article is meant as an introduction into how to parse RSS with Exact Target. I hope that this answers any questions you may have, but if you’d like more information, please leave a comment below and I’ll be sure to help you out.
Leave a Reply