So firstly this post comes about because I have been working with the Content Query Web Part quite a lot recently and this particular behaviour has been bugging me for ages.
However I have just got back from the European SharePoint Best Practices Conference where Christine Wheeler did some great sessions on the Content Query Web Part and I was hoping to ask her why the following behaviour happens.
However, just before I put my hand up she bet me to it and asked the audience if anyone knew why custom item styles don’t have friendly names and out of the box styles do.
So I thought I really should find out why.
So what the heck am I talking about?
Well its this section of the Content Query Web Part that is the problem:-
This custom item style “CustomItemStyle” template has an unfriendly name compared to the other out of the box styles.
This screen is reached in the Content Query Web Part by the following:-
- insert a content query web part on the page
- Modify its properties
- Expand the Presentation grouping and you will see two drop-down boxes
- Group Style and Item Style
The “Out of the Box” item styles are displayed as readable descriptive list items.
What commonly happens is that new styles need to be created as none of the out of the box styles give the format that is required. It is possible to create your own style by :-
- opening SharePoint Designer
- create a copy of the XSLT style sheet ItemStyle.xslt found in Site Collection Root/Style Library/XSLT Style sheets
- copy an existing item style template <xsl:template></xsl:template>
- give the <xsl:template name attribute a new name and change the match attribute to contain the same text as the name attribute.
Further information can be found in this great post (http://blogs.msdn.com/b/ecm/archive/2006/10/25/configuring-and-customizing-the-content-query-web-part.aspx) on the Microsoft ECM Blog.
There does not seem to be away to control the description and give a friendly name. Looking through the components that make up the Content Query Web Part it would make sense that one of the following style sheets would help:-
I would have expected ContentQueryMain.xslt to have some XSLT that would perform a look up which we could then add to allowing custom friendly ItemStyle descriptions.
So I started thinking well how does the Content Query Web Part get this information?
The best way to find out is to reflect the code.
The first place to look was at the class Microsoft.SharePoint.Publishing.WebControls.ContentByQueryToolPart the ToolPart is the control which displays the interface when you modify the web part settings on a SharePoint page.
The control has the following function, populateItemStylesDropDown() this calls back into the parent web part control using function PopulatedItemDropDown passing in the path ~SiteCollection/Style Library/XSL Style Sheets/ItemStyle.xslt.
The PopulateDropDown is then called with the XSLT Style Sheet link and also the “ItemStyle” string. It is this function where all the item styles are discovered and added to the drop-down list box.
If you look at the highlighted section the code tries to resolve a string within a resource file using the Item Style name attribute and prefixing the Item Style name with “ItemStyle”.
If a string is not returned then the template name found in the XSLT is used and hence this is why we see unfriendly style names with custom Content Query Item Styles.
So where are these Item Style names stored?
Well the function Resources.GetString() function is called and the Resources object is also found in the Microsoft.SharePoint.Publishing assembly as Type Microsoft.SharePoint.Publishing.Internal.Resources.
The class has a default constructor which defines the details of the resource file to open. It happens that the resources are actually held within the Assembly Microsoft.SharePoint.Publishing.Intl.dll which is found in c:\program files\microsoft office servers\14\bin directory.
The Microsoft.SharePoint.Publishing.Intl.dll has embedded resources, one of them being Microsoft.SharePoint.Publishing.Strings.resources, this contains all the Item Style resource strings.
So there you go, that is how the Content Query Web Part displays readable Item style descriptions!
The next question is how do we go about doing our own version of this?
That is something that I haven’t thought about yet. I would be interested in hearing from you on how you would approach this issue.