Wednesday, March 25, 2009

News v4.x Alternating color background...

by Phil 'iwonder' Guerra - (Mission, KS) - Sometimes you would like to change the look of your news feed presentation. One such possibility is alternating background color of a news feed item. It's fairly easy to do, but with the new version of the News module v4.x you must remember to fashion your new custom xsl to respect the parameters used in the module setup.

The simplest way to develop a custom xsl for the News v4.x module is to just copy the existing default.xsl which resides in the ~/DesktopModules/News/transformations folder. Use your favorite text editor and make whatever changes you need. Be careful to keep the parameters that are used in the default.xsl that match what is setup in the News v4.x module.

Now, after modifying your custom xsl, save the new file to your portals/n folder and change the module setting to use the new xsl. Always test your new xsl, either using a suitable XML/XSL editor, or in a test instance of your DNN site. Also, I find it works best to place your test News module in a special page of it's own, to avoid causing issues. If your test module fails to display with your new xsl, it could cause your site to 'freeze' or lock up, so you do not want to test a new moduel setup on your 'home' page.

Here's an example xsl that alternates the background of the items in a feed. Try it out and make it your own.

<?xml version="1.0" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<!-- alternating background color -->
<!-- for use with DNN News module v4.x -->
<!-- by Phil 'iwonder' Guerra' -->
<!-- 2008-09-21 -->
<xsl:output method="html" indent="yes" />
<xsl:param name="ItemsToShow" /> <xsl:param name="ShowItemDetails" /> <xsl:param name="ShowItemDate" />
<xsl:param name="Locale" />
<xsl:template match="rss">
<xsl:for-each select="channel/item[position()<=$ItemsToShow or $ItemsToShow<1]">
<div>
<xsl:if test="position() mod 2 != 0"> <xsl:attribute name="style">background-color: #F5F5F5</xsl:attribute>
</xsl:if>
<p class="DNN_News_ItemLink"> <a href="{link}" target="_blank">
<xsl:value-of select="title" /> </a>
</p>
<xsl:if test="$ShowItemDate='true'">
<p class="DNN_News_ItemDate">
<xsl:value-of select="pubDate" />
</p>
</xsl:if>
<xsl:if test="$ShowItemDetails='true'">
<p class="DNN_News_ItemDetails">
<xsl:value-of select="description" disable-output-escaping="yes" />
</p>
</xsl:if>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

1 comment:

Shawn said...

Hi Thanks for the article, I am wondering if there is a way to display news feed items in a simple calendar view? any ideas?

Post a Comment