cancel
Showing results for 
Search instead for 
Did you mean: 

RSS Feed Question

andream
Champ in-the-making
Champ in-the-making
RSS Feed Question - How do you define number of posts displayed on a RSS feed? The FTL file code we are using is below:

FYI: I'm not the developer. This was created by a IT contractor who helped us set-up our Alfresco CMS.

<#ftl ns_prefixes={"news", "http://www.webbynews.ca/news"}>
<#assign news = .vars["news:news"]>
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
   <channel>
      <title>Webby News</title>
      <link>http://www.webbynews.ca</link>
      <description>Webby News</description>

      <#assign articleList = null>
      <#list alf.parseXMLDocuments('Webby News', '/news/xml/') as x>
         <#assign xmlname = x["@alf:file_name"]>   
         <#assign article_path = "/news/xml/" + xmlname>
         <#assign listarticle=alf.parseXMLDocument(article_path)>
         <#assign jspLink = xmlname?string?substring(0, xmlname?string?index_of(".xml"))+ ".jsp">
         <#assign articleList = articleList+ [{"title":listarticle["news:title"],"articledate":listarticle["news:active"] ,"url":jspLink ,"body":listarticle["news:content"] }]>
       </#list>
      
      <#list alf.parseXMLDocuments('WEBBY NEWS', '/news/xml/') as x>
         <#assign xmlname = x["@alf:file_name"]>   
         <#assign article_path = "/news/xml/" + xmlname>
         <#assign listarticle=alf.parseXMLDocument(article_path)>
         <#assign jspLink = xmlname?string?substring(0, xmlname?string?index_of(".xml"))+ ".jsp">
         <#assign articleList = articleList+ [{"title":listarticle["news:title"],"articledate":listarticle["news:active"] ,"url":jspLink ,"body":listarticle["news:content"] }]>
       </#list>

      <#list articleList?sort_by("articledate")?reverse as i>
         <item>
            <title>${i.title?string?replace("&","&amp;")}</title>
            <link>http://www.webbynews.ca/news/articles/${i.url}</link>
            <description>${i.body?string?replace("<","&lt;")?replace(">","&gt;")}</description>
         </item>
      </#list>
   </channel>
</rss>
1 REPLY 1

scouil
Star Contributor
Star Contributor
Hi,

As you may know, this file is formatted with freemarker. And your articleList is a freemarker sequence.
So what you need to do is restrict this sequence to the X first elements.
To do so, please have a look at:
http://stackoverflow.com/questions/18458417/get-sub-list-from-a-list-in-freemarker

If you need it to be modifiable through a parameter, you can just retrieve parameters with the "args" root object

so your webscript would just need a one-line change:
<#list (((articleList?sort_by("articledate"))?reverse)?chunk((args["maxEntries"]!"20")?number))?first as i>

I added parentheses for clarity. AndAssumed a default value of 20 entries when the maxEntries parameter is not specified

I didn't test it so if it causes any syntax error please come back