I am trying to create a content block in email-studio, using xml/rss feed to import content for display.
I've used both (1) creating a standalone content block, and (2) inserting a code snippet content block into an email. The 'preview' function in the editor for the former just shows me part of the code itself, no output. The 'preview email' function in the latter just shows a blank slot (or, truncates the message).
I'm using:
- [https://salesforce.stackexchange.com/questions/277948/rss-feed-via-ampscript]
- [https://salesforce.stackexchange.com/questions/254076/ampscript-rss-feed]
- https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/rssFeedEmail.htm
I tried using the developer help code first, and that didn't work. I'm now using a slight edit from the first one (as below). I did use https://www.ampscript.io/ to review the code, but I haven't been able to fix it from that.
/* adjust if pubDate conditional to -14 for last 14 days, -300 last 300 etc */
%%=now(1)=%%
%%[
var @xml, @isXML, @nodes, @rowCount
set @xml = HTTPGet("https://lorem-rss.herokuapp.com/feed", false, 0, @CallStatus)
/* strip out invalid elements if needed */
/* set @xml = Replace(@xml, "dscblog:","") */
output(concat("<br>Call Status: ", @CallStatus))
if indexOf(@xml,"<channel>") > 0 then
set @nodes = BuildRowsetFromXML(@xml,"/rss/channel/item",0)
set @rowCount = rowcount(@nodes)
output(concat("<br>rowCount: ", @rowCount))
set @rowCount = iif(@rowCount > 5, 5, @rowCount)
output(concat("<br>rowCount (adj): ", @rowCount))
if @rowCount > 0 then
for @i = 1 to @rowCount do
var @pubDate
var @title
var @description
var @link
set @nodepath = concat("/rss/channel/item[",@i,"]/")
if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath,"pubDate"))) > 0 then
set @pubDate = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"pubDate"),0),1),'Value')
set @pubDate = SystemDateToLocalDate(@pubDate)
endif
if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath,"title"))) > 0 then
set @title = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"title"),0),1),'Value')
endif
if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath,"description"))) > 0 then
set @description = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"description"),0),1),'Value')
endif
if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath,"link"))) > 0 then
set @link = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"link"),0),1),'Value')
endif
if @pubDate >= DateAdd(Now(1), -300, "D") then
]%%
<h4>%%=v(@title)=%%</h4>
%%=v(@pubDate)=%%
<p>
%%=v(@description)=%%
<br><a href="%%=redirectto(@link)=%%">%%=v(@link)=%%</a>
</p>
%%[
endif
next @i
else
outputline(concat("<br>no items found"))
endif
else
outputline(concat("<br>no XML found"))
endif
]%%