Sample RSS Feed

Overview

Building an RSS feed is very straightforward in ColdFusion. The trick in FarCry Framework is knowing where to put the code. This example is taken directly from the Fullasagoog website.

Suitable for applications running FarCry Core 5.1+ and ColdFusion 8+ (example requires CFFEED)

Fullasagoog RSS Feed

This example is taken from the Fullasagoog RSS feed:

The site has a content type called googBlogPost which contains data about individual blog posts aggregated from the web.

Building a Feed

A feed is essentially a collection of content items, for example blog posts. When you are thinking of a collection of objects you should be using a "type webskin" (aka a Collection or List View). The type webskin applies to the entire content type and not just an individual instance of that type.

Type webskins do not have the standard stobj property structure. They typically start with a call to the database for a group of content items. In this example we have a query inline that grabs relevant session objectids. You may want to encapsulate such a query in a function call.

View Security

Depending on your installation, you may need to ensure that the view feedRSS.cfm is actually visible to anonymous users. By default only views prefixed with display and execute are available. You can add the view to the anonymous role by logging into the webtop. Go to ADMIN > Roles > View permissions and add the feed* prefix to the list available.

Complete Code

You Must Change the Code To Suit Your Application

Obviously you can't just grab this code and plonk it into your own site. You will need to look at the structure of the code and make changes accordingly. It's here for demonstration purposes only, and to kick start your own development.

./webskin/googblogpost/feedRSS.cfm
<cfsetting enablecfoutputonly="true" /> 
<!--- @@Copyright: Copyright (c) 2008 Daemon Pty Limited. All rights reserved. --->
<!--- @@displayname: RSS Feed--->
<!--- @@description: Type webskin for RSS feed for the latest blog posts in the Goog. --->
<!--- @@author: Geoffrey Bowers on 2008-12-15 --->
<!--- @@cacheStatus: 1 --->
<!--- @@cacheTimeout: 15 --->

<cfquery datasource="#application.dsn#" name="qPosts">
SELECT TOP 30 objectid, datetimepublished, description, title
FROM googBlogPost
ORDER BY datetimecreated DESC
</cfquery>

<!---<cfdump var="#qPosts#">--->


<cfset qFeed = queryNew("title, content, publisheddate, rsslink") />
<cfloop query="qposts">
	<cfset queryaddrow(qFeed, 1) />
	<cfset querysetcell(qFeed, "title", qPosts.title) />
	<cfset querysetcell(qFeed, "content", abbreviate(qPosts.description, 300)) />
	<cfset querysetcell(qFeed, "publisheddate", qPosts.datetimepublished) />
	<cfset querysetcell(qFeed, "rsslink", application.fapi.getLink(objectid=qPosts.objectid, view="displayRedirect")) />
</cfloop>

<!--- Set the feed metadata. --->
<cfset stprop = StructNew() />
<cfset stprop.title = "Fullasagoog" />
<cfset stprop.link = "http://fullasagoog.com/" />
<cfset stprop.description = "The lastest goog flavoured blend, chock full of rich internet application goodness." />
<cfset stprop.version = "rss_2.0" />

<!--- Create the feed. --->
<cffeed 
	action="create"
	query="#qFeed#"
	properties="#stProp#"
	xmlvar="rssXML" />

<cfcontent reset="true" /><cfoutput>#rssXML#</cfoutput>


<!---<cfdump var="#XMLParse(rssXML)#">--->

<cfsetting enablecfoutputonly="false" />