RSS Feed Display Template - Example of <if> Statements and Escaping Characters Coding
Using <if> statements in an RSS feed display template allows the template to be applied to different external RSS feeds containing different fields. (The specified format -- RSS2, RSS1, or ATOM -- must still match.) This is particularly useful if you plan to display multiple external RSS feeds from different sources. With <if> statements, you can minimize the number of templates you create and maintain.
Special characters, such as elements containing namespaces, must be quoted and escaped as such:
<t:if test="'dc\\:description' !=null">
To conditionally include or exclude a field:
The following code specifies that the Description field for an external RSS feed item (listed on a live page) will display only if it has a value. If the external feed has no Description field, or a feed item has no Description value, the feed item will not display that field.
<t:list id="rss.channel.item">
<p>************************</p>
<a href="${link}">${title}</a>
<p>Published On:${pubDate}</p>
<p>
Published on:
<t:value id="pubDate" format="3">Jan 1, 2009</t:value>
</p>
<t:if test="description !=null">
<p>Here's the description</p>
<p>${description}</p>
</t:if>
<t:else>
<p>There is no description</p>
</t:else>
</t:list>
To limit the number of displayed feed items:
- Use an <if> statement to limit the number of items displayed from a feed:
<t:if test="index<4">...</t:if>
<t:if test="index<4">...</t:if>