Flexible Content Areas with XML Interfaces

Here is a good way to display a grid of external content in an email without repeating a significant amount of AMPScript. It utilizes an XML string and uses XPATH to retrieve content using the BuildRowSetFromXML() function.

Connections 2014 PPT presentation

Helful Links/Resources

Double Wide v2 – Responsive Email Pattern
XPATH reference
All AMPScript Functions
LookupOrderedRows() Function
BuildRowsetFromXML() Function
TreatAsContent() Function
ContentAreaByName() Function

Email Init Section

%%[

set @products = LookupOrderedRows("ProductDE",6, "AvgCustomerRating desc" ,"ApprovedForEmail","true")
set @productCount = rowcount(@products)

set @productXML = "<products>"

for @i = 1 to @productCount do

    set @product = Row(@products, @i)

    set @productImageURL = Field(@product, "ProductImageURL")

    set @productXML = concat(@productXML,"<product>")
    set @productXML = concat(@productXML,"<productImageURL><![CDATA[",@productImageURL,"]]></productImageURL>")
    set @productXML = concat(@productXML,"</product>")

next @i

set @productXML = concat(@productXML,"</products>")

]%%

Email Body

<html>
<body style="font-family:sans-serif">

%%[ set @productPos = 1 ]%%
%%=TreatAsContent(ContentAreaByName("My Contents\ProductDisplay"))=%%

%%[ set @productPos = 2 ]%%
%%=TreatAsContent(ContentAreaByName("My Contents\ProductDisplay"))=%%

%%[ set @productPos = 3 ]%%
%%=TreatAsContent(ContentAreaByName("My Contents\ProductDisplay"))=%%

<a href="%%profile_center_url%%">Profile/Preference Center</a>
<br/><a href="%%subscription_center_url%%">Subscription Center</a>
<br/><a href="%%unsub_center_url%%">One-Click Unsubscribe</a>
<p>This email was sent by:
<b>%%Member_Busname%%</b>
<br/>%%Member_Addr%% %%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%</p>
<custom name="opencounter" type="tracking">
</body>
</html>

Content Area Init Section

%%[

set @node = BuildRowsetFromXML(@productXML,concat("/products/product[",@productPos,"]/productImageURL"),1)
set @productImageURL = Field(Row(@node, 1),'Value')

]%%

Content Area Body

<img src="%%=v(@productImageURL)=%%" width="150" border="1" style="display: block;">

Questions? Comments? Feel free to leave a comment below.