I got a message from a pal (@AndrewJolly) asking if I knew anything about displaying the contents of a Links List in the Content Query Web Part (CQWP). I vaguely remembered having had some difficulties with this in the past so I thought I’d take a quick look into it. The good news is that it is possible to get it to display as expected, without having to resort to any custom code or XSL!
How to do this? Well first let me run through the steps I tried. Firstly creating a quick links list on an out of the box publishing site and adding a few entries.
Now, adding a CQWP to the page and simply configuring the query to point at my particular list, and setting the display style to ‘Bulleted title’, and I get this strange list of blank links. Huh.
Figuring that this is showing ‘(blank)‘ because the list item content type has a hidden title field, which therefore doesn’t get populated, I looked at changing the configured slots on the web part. What are slots? Slots are a great new feature of the SharePoint 2010 content query web part which allows you to match different fields to the variables used in the XSL – therefore giving you an extra degree of separation between the presentation and the data; and allowing for greater re-use.
Configuring the slots is as easy as adding the column name into the Fields to display section. So configuring the slots to use the URL column for the title I tried again. At the same time, I also pointed the Link slot with the URL column as the previous attempt linked me through to the display form of my list item – not the actual link I’d entered.
So close! But still not quite right. The link is now working as expected, i.e. taking me through to Bing or Google etc, but the display is not correct. By taking the URL column out of the Title slot and leaving it blank I can have the full URL displayed (which may even be desired in some scenarios) – but this is still not what I’m really after.
Taking a step back and looking at this and it seems clear that the root cause of my problem is that the value that I’m looking for, e.g. just the link title, is not stored in its own column; rather it is one part of the whole link column. In the past I’ve addressed this and similar issues by creating my own presentation style in custom XSL – see my extended content query web part post.
Without wanting to create custom XSL for such a simple request I looked at other options. Looking at the root cause then it seems that the simplest option is to add in the title of the links into its own column! I used the existing Notes column for this, all though it would be just as easy to add a new column to your list and use that.
So (nearly there now) by adding in the title data into the Notes column in my links list, and now setting the title slot to use that column we get the links list displayed in the content query web part as we’d have expected it to!