The Content query web part is a wonderful way to aggregate data into a page. A common use of it is to show "news" pages in the home page of a publishing site. This is well enough, and it even has several styles to pick from :
If you want to customize one of the styles or create your own you can do that by editing the xslt data
Some of the built-in styles include the description field and display it, but my problem was that the description was plain text. It even ignored line breaks that the users wrote. And that is a big problem if you want a summary of the article in your home page with a "read more..." link. For example, if the description the user wanted on the home page was:
He would instead get:
Solution?Since the pages sit in a document library, and since document libraries do not support rich text fields (damn it!), I had to think of a quick and ugly solution - paste html text into the description. So if the description was to be:
the user had to paste the html equivalent:
So I tried this, and found a flaw. The Content Query web part would display the text as-is and would not format it as rich html.
XSL to the rescue
To resolve this, there is a simple tweak you can do on the itemstyle.xsl file in the site. Open the site in SharePoint Designer, and navigate to the "Style Library" folder, and into the "XSL Style Sheets" folder. Check out and open the ItemStyle.xsl file, and in it find the style that you are using in the webpart, where you want to display the description as rich text.
A quick way to do that would be to search the file for the text
<xsl:value-of select="@Description" />
disable-output-escaping="yes" inside the tag, so that the end result is:
<xsl:value-of select="@Description" disable-output-escaping="yes" />
With this quick change, the html code the user inputs in the description field will be displayed as rich text. The only danger in this is that the user will make a mistake, not close one of the fields and cause havoc on the page. So make sure your users are aware of the risk, and maybe write an event handler or workflow to validate the html. I would recommend just implementing an approval workflow that checks the validity of the html.