Build XML/RSS from Content

Last Updated: Jun 11, 2019
documentation for the dotCMS Content Management System

This is an example of how to build an xml/rss feed from a pull of content. Here is an example of how the content can be pulled using the dotContent Tool and displayed as XML channel subscription.

The code also shows how to get a category from a url and filter the content using the category fed to the page:

#if($request.getParameter("cat"))
  #set($catVar=$request.getParameter("cat"))
  #set($catQuery = "+(categories:$catVar)")
#end

#set($nowsers= $date.format('yyyyMMddHHmmss', $date.getDate()))
#set($finalQuery = "+structureName:Blog $!{catQuery} +Blog.sysPublishDate:[19001010101000 TO $nowsers]")

<b><?xml version="1.0" encoding="utf-8"?></b>
<b><rss version="2.0" xmlns:jf="http://${host.hostname}/blogs/rss"></b>
<b><channel></b>
<b><title></b>Quest Financial Blogs</title>
<b><link></b>http://${host.hostname}/blogs/</link>
<b><description></b>Most Recent $!{catVar} - Quest Financial Blog</description>
<b><language></b>en-US</language>
<b><pubDate></b>$!{date.format('yyyy-MM-dd', $date.getDate())}T$!{date.format('hh:mm:ss', $date.getDate())}</pubDate>

#set($blogContent= $dotcontent.pull("${finalQuery}",50,"Blog.sysPublishDate desc"))  
#foreach($blogEntry in $blogContent)
<b><item></b>
  <b><title></b>$webapi.xmlEscape($!{blogEntry.title})</title>
  <b><description></b>$webapi.xmlEscape($UtilMethods.prettyShortenString("$blogEntry.body", 200))</description>
  <b><link></b>http://${host.hostname}/blog/$blogEntry.urlTitle</link>
  <pubDate>$!{date.format('yyyy-MM-dd', $blogEntry.sysPublishDate)}T$!{date.format('hh:mm:ss', $blogEntry.sysPublishDate)}</pubDate>
  <guid>http://${host.hostname}/blog/$blogEntry.urlTitle</guid>
</item>
#end
<b></channel></b>
<b></rss></b>

On this page

×

We Dig Feedback

Selected excerpt:

×