Tom Muck

Alpha Dog Blues Band
Home page
All articles
All Extensions | Extension News | Extension FAQs | Customer Login
Books authored or co-authored by Tom Muck
Extensions, books, and other products | Customer Login
Your current cart contents Blog | CMXTraneous Blog | Flash Remoting Blog
About the site


Tom Muck's BlogTom Muck's Blog

News and Views

Custom tag for RSS feed in ColdFusion

Wednesday, October 05, 2005 8:21:24 PM

I wrote a simple ColdFusion custom tag last night that you might find useful. The tag will generate an RSS feed. You pass a recordset/query to the tag and it will spit out an RSS feed. It is based partly on the RSS feeds I built for this site and Community MX, and also based on the custom tags I built for generating dynamic tables and csv files. Like the others, it is a rudimentary tag that you can build on.

Use the custom tag like this:

1. Put it in a directory where custom tags are stored. I usually just create a folder called tags and put all my tags inside. Save it as rss.cfm.

2. On the page that will become your RSS fed, add an import statement to the top of the file:

<cfimport prefix="mytag" taglib="tags">

3. Create your query:

<cfquery name="blah" datasource="#mydsn#">
SELECT NewsID, NewsDate, NewsTitle, NewsItem FROM MyTable

4. Put the tag on the page, passing in the results of the query:

<mytag:rss rs=#blah#>

If you browse the page, the RSS should be visible.

There are several optional attributes, which are outlined below:


rs: Recordset/query to use for the RSS file (default: new query)

title: title tag in channel (default: RSS)
link: link tag in channel (default: http://#cgi.SERVER_NAME#)
description: description tag in channel (default: RSS feed for
webmaster: webmaster tag in channel (default:

items: Struct of item field names (default: structnew())
items.title: Field name for title of RSS item (default: title)
items.description: Field name for descriptionof RSS item (default: description) Field name for link of RSS item (default: link)
items.pubdate: Field name for pubdate of RSS item (default: pubdate)

items.permalink: http address for link with ID from database (default: http://#cgi.SERVER_NAME#/?id=) Primary key for picking record

striphtml: strip the html tags from the item (true/false, default: false)
wordcount: truncate item to number of words (default: empty string for no truncation)
maxrows: show x number of rows (default: empty string for all records)
debug: true/false value for debugging the feed (true turns of text/xml content type)
xslt: name of an XSL transformation file (default: empty string for no transformations)

If the query has the proper field names for an rss file (title, description, pubdate, link, and id for the primary key) you don't need to pass in field names. If your blog or news query uses completely different fieldnames, simply set them up in a struct before calling the tag, like this:

<!--- Create the query --->
<cfquery name="rsNews" datasource="#request.dsn#">
SELECT NewsID, NewsDate, NewsTitle, NewsItem FROM Blog

<!--- Set up the field name mapping --->
<cfset fieldmappings = StructNew()>
<cfset fieldmappings.pubdate = "NewsDate">
<cfset = "NewsID">
<cfset fieldmappings.title = "NewsTitle">
<cfset fieldmappings.description = "NewsItem">
<!--- Call the cf_rss tag --->
<mytag:rss rs=#rsNews# items=#fieldmappings#>

Alternatively, you can avoid the import statement and use old-style cf_ syntax:

<cf_rss rs=#blah#>

You can also pass in the name of an XSL transformation file. A sample file is included in the zip:

<mytag:rss rs=#rsNews# items=#fieldmappings# xslt="rss.xslt" >

I hope you find it useful. See it in action here. View the source here or download it here.

Category tags: Dreamweaver, ColdFusion

Before posting comments or trackbacks, please read the posting policy.

Full Blog Calendar

Pay me securely with your Visa, MasterCard, Discover, or American Express card through PayPal!
Pay me securely with your Visa, MasterCard, Discover, or American Express card through PayPal!
About | Privacy Policy | Contact | License Agreement | ©2002-2024 Tom Muck | Dreamweaver Extensions