Inconvenient Content Query Web Part slots
Content Query Web Part, Customization, Inconvenient SharePoint, SharePoint 2010We all know Content Query Web Part (CQWP) – probably the greatest Web Part provided with SharePoint Server that allows you to build dynamic content aggregations in a matter of minutes. CQWP is known not only for its great performance but also for its flexibility and extensibility capabilities. In SharePoint Server 2010 Content Query Web Part introduces even more functionality among which the slots – a cool feature that allows you to create semantic and reusable templates. And while creating new templates became as simple as it was never before there is one thing that you should keep in mind while working with Content Query Web Part slots.
Slots – and it’s not about Vegas
Slots are new capability of Content Query Web Part introduced with SharePoint Server 2010. Slots allow you to create semantic and reusable presentation templates. Where you had to cast some magic spells in Office SharePoint Server 2007 to get custom Item Style templates work with your custom Content Types, you can benefit of slots in SharePoint Server 2010 and create new Item Style template in the matter of minutes.
How it works?
First of all you start off by creating a new Item Style template just as you would with Office SharePoint Server 2007 – nothing new here. But then the magic happens. As soon as you pick your custom Item Style template in the Web Part properties, CQWP parses the selected template and generates slots for it: every @SomeProperty becomes a slot:
<xsl:template name="DetailedOverview" match="Row[@Style='DetailedOverview']" mode="itemstyle">
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="DisplayTitle">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="''"/>
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
<xsl:with-param name="UseFileName" select="1"/>
</xsl:call-template>
</xsl:variable>
<p>
<strong><xsl:value-of select="$DisplayTitle"/></strong><br />
<xsl:value-of select="@Author"/>, <xsl:value-of select="@Date"/>
</p>
<p>
<xsl:value-of select="@RollupImage"/>
<xsl:value-of select="@Details"/>
</p>
<p>
<a href="{$SafeLinkUrl}">Read more</a>
</p>
</xsl:template>
will generate the following slots:
You can now bind one or more fields to every slot by providing their display names. If the value of the first field is empty, CQWP will look for the value of the next one. This is extremely useful when aggregating items of different Content Types.
Using slots allows you to create reusable Item Style templates. Because the binding with the fields is being done through Web Part’s settings, you can reuse your existing templates across different projects what allows you to standardize your solutions and simplify the maintenance.
There is however one thing about slots that doesn’t work as you would expect it to…
Inconvenient description
Probably one of the most commonly used content aggregation templates is the one where you display the title, some short description and a link that takes the visitor to the full content.
In such overview the title is being retrieved from the Title field and the short description from the Description (internal name: Comments) field. So how come that it doesn’t work?! No matter if you provide the display name (Description), Internal Name (Comments) or Display Name and the Group Name (Comments [_Hidden]) you won’t see the description:
It turns out that there is an “undocumented feature” in SharePoint 2010 and it has to do with how the fields are being bound to the slots.
The problem
Right after you enter the names of the fields and hit the Apply button, the Content Query Tool Part starts resolving the bindings. For every field it asks the Content Query Web Part to return the binding information. Content Query Web Part uses for this purpose the list of all Site Columns and this is where the problems begin.
If you request the binding information for the Site Column with display name Description the CQWP will return:
{3f155110-a6a2-4d70-926c-94648101f0e8},Description,Note;
which is the Description field indeed, however it is not the Comments field which we know from the Page Content Type (ID: 9da97a8a-1da5-4a77-98d3-4bc10456e700).
If you however look further at the Content Types you will see that the Description field is in fact called Comments:
If you however request a binding for the Comments field you will still get a binding different than the one you need:
{691b9a4b-512e-4341-b3f1-68914130d5b2},ShortComment,Text;
It turns out that there are three columns with display name Comments: ShortComment, Comments and _Comments. You could try to solve this problem by adding the group name, such as:
Comments [_Hidden]
which allows you to distinguish between different Site Columns with the same display name. The problem is however that there are actually two Site Columns called Comments in the _Hidden group: ShortComment and Comments. And since the ShortComment Site Column is being added first to the array it gets picked up by the Content Query Web Part and as a result you end up with an invalid binding.
The workaround
You could work around this issue by fixing the binding generated by the Content Query Web Part. After configuring the CQWP, you would export it and modify the value of the DataMappings property.
By setting the value to the right ID, internal name and type, you could make the CQWP to work as expected. However as soon as someone edits the Content Query Web Part and hits the Apply button, your binding will be broken again. Not much of a reliable solution, is it?
Real solution?
In order to really deal with this challenge you have two options.
First of all you can change the display name of either the ShortComment or the Comments column. Because SharePoint uses ID’s and/or internal names for references this should work properly. The risky part is that both columns are standard SharePoint columns and you never know if there is something that relies on the display name. As a result, while fixing one issue, you might just be causing another.
Another solution is not to use the standard Comments field at all and create a custom Site Column which you will use for including short description. In this approach you can be sure that nothing else will break as you are using your own custom Site Column. The downside is that you cannot use the standard field that is already there.
Summary
Content Query Web Part in SharePoint Server 2010 introduces new concepts called slots. Using slots you can easily create semantic and reusable Item Style templates. While slots simplify working with Content Query Web Part you should consider which Site Columns you use for storing content as they might conflict with standard columns provided with SharePoint.

















May 1st, 2010 at 10:40 pm
[...] Dit blogartikel was vermeld op Twitter door EndUserSharePoint en Waldek Mastykarz, Marc D Anderson. Marc D Anderson heeft gezegd: RT @waldekm: New post: 'Inconvenient Content Query Web Part slots' http://tinyurl.com/246dcqy #SharePoint -> I still prefer DVWPs! [...]
May 2nd, 2010 at 10:50 am
[...] Dit blogartikel was vermeld op Twitter door EndUserSharePoint, Waldek Mastykarz, Planet SharePoint, Marc D Anderson, Erik Neumann en anderen. Erik Neumann heeft gezegd: #sharepoint Inconvenient Content Query Web Part slots: We all know Content Query Web Part (CQWP) – probably the gr… http://bit.ly/92x6pi [...]
May 2nd, 2010 at 4:33 pm
Got the same issue a few weeks ago for a client project I'm working on. Took me quite a long time to figure it out why it was working with ootb xslt and then no more using mine…
I ended up changing the DataMappings property after figuring out it was the culprit.
Trhanks for this nice explanation. I'm pretty sure a bunch of people will fall in this trap.
May 2nd, 2010 at 4:33 pm
Got the same issue a few weeks ago for a client project I\'m working on. Took me quite a long time to figure it out why it was working with ootb xslt and then no more using mine…
I ended up changing the DataMappings property after figuring out it was the culprit.
Trhanks for this nice explanation. I\'m pretty sure a bunch of people will fall in this trap.
May 2nd, 2010 at 11:14 pm
[...] Dit blogartikel was vermeld op Twitter door EndUserSharePoint, Waldek Mastykarz, Planet SharePoint, Neil_Parker, Marc D Anderson en anderen. Marc D Anderson heeft gezegd: RT @waldekm: New post: 'Inconvenient Content Query Web Part slots' http://tinyurl.com/246dcqy #SharePoint -> I still prefer DVWPs! [...]
May 31st, 2010 at 8:44 am
Is it possible to override the CQWP (a la SP 2007) to fix this behaviour?
May 31st, 2010 at 4:59 pm
@Alex: First of all it's the ContentQueryToolPart that's causing the issue, not the CQWP itself. Then, I believe, that the method that's causing the trouble is private so you would have to do quite some work to get this work properly. Changing the display name of one of the Description fields seems to be the easiest way.
December 14th, 2010 at 1:32 pm
Is the above maybe also related to managed metadata column types? When using a slot to get the value of the selected metadata in the cqwp it is not showing the data. Or am I assuming it wrong to expect a textual representation of the selected metadata?
December 14th, 2010 at 1:43 pm
@Ben: did you check if the data is included in the results XML?
December 17th, 2010 at 2:44 pm
@Walkdek: I recreated the managed metadata site columns and it worked instantly , don\'t know where it did go wrong. So luckily its possible to use it :) thanks for the response!
January 6th, 2011 at 12:18 pm
Hi Waldek,
Firstly, thanks for the great post.
Secondly, I have a quick question:
I would like to display the content of a managed metadata field in the CQWP and was wondering what field type to use in the CommonViewFields property when configuring the .webpart file.
Thanks.
January 6th, 2011 at 12:24 pm
@Francois: You can use either Server Explorer in Visual Studio 2010 SharePoint Developer Tools or PowerShell to discover the field type.
January 6th, 2011 at 12:59 pm
Thansk Waldek,
After more trial and error and I actually found that editing CommonViewFields in the .webpart is now longer needed (as with SharePoint 2007). Now you simply update the XSLT with the "@" slots and then add the column name into the web part itself.
January 6th, 2011 at 1:17 pm
@Francois: if the only thing you want to do is to display the values, using slots is indeed the only thing you need. You might be still needing CommonViewFields if you would like to include the values in RSS.
April 3rd, 2011 at 10:41 pm
Using the CQWP, I have a simple rollup of recent discussion items in a site. However, I dont see how to change the URL to each item. Its goes to CopyUtil.aspx (which redirects to DispForm.aspx) and I would rather it go to the Flat.aspx or Threaded.aspx view of the items folder. How does one change the settings or XSL to specify this. I think this post gets me closer, but I'm still not there yet. Any help is appreciated.
Thanks.
Peter Meeks
April 4th, 2011 at 5:13 am
@Peter: I'm not sure you will able to achieve this using CopyUtil. The CopyUtil is only able to redirect to either edit or display form. What you could do is to create a custom HTTP Handler that would be comparable to the CopyUtil page but then would redirect to the selected view of the discussion list.
October 26th, 2011 at 7:33 pm
Hi,
I have 2 questions here. 1) Francois stated he was able to display a managed metadata field in cqwp by adding a slot for it with XSLT. I have tried to do the same thing, but none of my MM fields display anything after I've entered in a value. For example, I have a MM Field called "Agency Lookup". In XSLT I've added . This creates the slot for my cqwp, but when I add "Agency Lookup" to the CQWP, nothing is displayed. Could the reason this MM field allows multiple values be the issue?
2) I've added another slot in xslt for the "AssignedTo" field which is part of the Core Task and Issue Columns group. In the cqwp, the slot is dislayed, but when I add the display name "Assigned To" for column name, nothing shows up. I've also tried adding "Assigned To [Core Task and Issue Columns]", "AssingedTo", "Assigned [_Hidden]" in the cqwp to no avail. I don't understand why this field type doesn't show up, but if I use "CreatedBy" or "Author", they do show up. Thoughts?
October 27th, 2011 at 7:14 am
@Beth: 1) As far as I know you can work with MM Fields only when the query scope is set to specific List.
2) That sounds odd indeed. It isn't something I have stumbled upon unfortunately.
October 27th, 2011 at 4:43 pm
@Waldek. Thanks for the quick response and clarification about MM Fields! That makes sense. I'll keep you posted if I resolve issue (2).
Beth
December 7th, 2011 at 1:35 pm
A colleague Sharepoint developer (http://www.akshaykoul.com/blog/) gave me the solution
-Export OOTB CQWP
-Edit .webpart file and change existing element by this :
Description:{691b9a4b-512e-4341-b3f1-68914130d5b2},ShortComment,Text;|SipAddress:|Title:{fa564e0f-0c70-4ab9-b863-0177e6ddd247},Title,Text;|OpenInNewWindow:|Date:|ImageUrl:{b9e6f3ae-5632-4b13-b636-9d1a2bd67120},EncodedAbsThumbnailUrl,Computed;{543bc2cf-1f30-488e-8f25-6fe3b689d9ac},PublishingRollupImage,Image;|LinkUrl:{94f89715-e097-4e8b-ba79-ea02aa8b7adb},FileRef,Lookup;|LinkToolTip:|
{94f89715-e097-4e8b-ba79-ea02aa8b7adb},Lookup;{b9e6f3ae-5632-4b13-b636-9d1a2bd67120},Computed;{543bc2cf-1f30-488e-8f25-6fe3b689d9ac},Image;{fa564e0f-0c70-4ab9-b863-0177e6ddd247},Text;{691b9a4b-512e-4341-b3f1-68914130d5b2},Text;
Comments,Note;
Comments,Description
Upload your custom webpart and add this to your page :)
Laurent
ps : thanks for this blog
January 12th, 2012 at 3:37 am
Hi Waldek,
Thanks for the solution. I've used slots for 2 features on our site already.
Trying to use it for a third (a list-driven accordion web part) works great except for one showstopper. I have a required Rich Text Field column in the list. When rendered on the page the mark up from the ribbon formatting is rendered as content. So container divs, font styling, urls, etc render as text strings not functional mark up.
Have you successfully used a Rich Text column as a slot?
January 16th, 2012 at 4:20 pm
http://maulikdhorajia.blogspot.com/2012/01/sharepoint-custom-toolpart-properties.html