Skip to content

RC.CompileFeed explained

Jorge Reyes edited this page Jun 3, 2015 · 2 revisions
<cfset rc.compileFeed = getPlugin('feedGenerator')
        .createFeed( FeedStruct=rc.feed, OutputFile='#getSetting("ApplicationPath")#includes/xml/my_first_feed.xml' )/>
  • rc.compileFeed - Name of the variable to save the generated feed to. This is optional.
  • getPlugin('feedGenerator').createFeed() - ColdBox feedGenerator plug-in requesting the createFeed() method.
  • feedStruct = rc.feed - Is the structure containing the feed Metadata as well as the feed item, query data.
  • outputFile='#getSetting("ApplicationPath")#includes/xml/my_first_feed.xml') - The full file path to an XML, which will be used to save the generated feed

Now everything is nearly ready for our feed. All we have to do is create our model which will contain the feed data. So save the following code to a file in the model directory named feeditems.cfc.

<cfcomponent name="feeditems" hint="A feed items data object">

  <cfset variables.instance = structNew()/>
  <cfset variables.instance.items = QueryNew("Author,Description,Link,Title")/>

  <cffunction name="init" access="public" returntype="feeditems" output="false">
    <cfreturn this>
  </cffunction>

  <cffunction name="generateItems" access="public" returntype="query" output="false">
    <cfset var returnQuery = variables.instance.items/>
    <cfset QueryAddRow(returnQuery,3)/>
    <---  Create our first item --->
    <cfset QuerySetCell(returnQuery, "Title", "Our first ColdBox feed item!", 1)/>
    <cfset QuerySetCell(returnQuery, "Description", "Congratulations you have successfully created your first ColdBox feed.", 1)/>
    <cfset QuerySetCell(returnQuery, "Link", "http://www.example.com/article/1", 1)/>
    <cfset QuerySetCell(returnQuery, "Author", "[email protected] (Ben Garrett)", 1)/>
    <---  Item 2 won't have an author but that is okay as it is optional --->
    <cfset QuerySetCell(returnQuery, "Title", "Optional tags", 2)/>
    <cfset QuerySetCell(returnQuery, "Description", "In this item we have choosen to leave out the author tag.", 2)/>
    <cfset QuerySetCell(returnQuery, "Link", "http://www.example.com/article/2", 2)/>
    <---  Item 3 --->
    <cfset QuerySetCell(returnQuery, "Title", "Broken links", 3)/>
    <cfset QuerySetCell(returnQuery, "Description", "Don't click those example links. They are fake, but are design to to give you an example when implementing your own feeds.", 3)/>
    <cfset QuerySetCell(returnQuery, "Link", "http://www.example.com/article/3", 3)/>
    <cfreturn returnQuery/>
  </cffunction>

</cfcomponent>
Clone this wiki locally