2

I'd like to customize the way a content query web part (CQWP) displays a list on SharePoint 2010; the list is defined in the root and is going to be fetched in a subsite. Each subsite will pull one record from the list and so we need to display it like this:

Contact [Department Name]
Address (MAP) 
Tel: 0000
[email protected]

Opening Hours:

​Sunday - Wednesday ​00:00 to 00:00 
​Thursday  ​​00:00 to 00:00 

The reason for using a CQWP is that we're pulling a list from the root and displaying it based on a department filter in a subsite. How difficult is it to customize a CQWP to display information this way? Thanks.

2 Answers 2

2

It's surprisingly easy to do what you need once you know the bits and pieces you need to do.

First, understand that the CQWP uses a file called ItemStyle.xsl which lives in the Style Library. This file contains templates which render the individual rows of a result of a CQWP.

Therefore, what you want to do, is to add a template to this file.

Next, if you haven't guessed, you'll need to employ some XSLT magic to the ItemStyle file to display it the way you want. Not only will this require XSLT knowledge, but also fundamental HTML (your layout hasn't much complicated about it, so you can get away with just a couple of <P> tags).

Here's a starter article on the ItemStyle, many more can be found with a quick Google: http://msdn.microsoft.com/en-us/library/bb447557.aspx

4
  • Thank you, James. You're answering so many question around here! My only issue now with going with changing the ItemStyle.xsl is that it will break the connection to the site definition. What are the risks of doing this?
    – Alex C
    Aug 7, 2011 at 13:38
  • 1
    No worries :) The main risk is that if you upgrade your environment to vNext, the instance of ItemStyle.xsl that you've changed won't see any new improvements that vNext brings, as it'll be detached from the environment. This can be anticipated and taken care of though. If you download a copy of that, revert that file to the site's definition, do the upgrade, then merge your changes into the newer file, you'll be fine.
    – James Love
    Aug 7, 2011 at 14:51
  • Is this an approach you'd recommend? astaticstate.com/2011/05/… It's a custom ItemStyle file, separate from the original.
    – Alex C
    Aug 8, 2011 at 5:02
  • 1
    Yes, it is, and it's one I use. It jsut has the added complexity that you need to export an existing CQWP instance to wire it up to your new, custom ItemStyle file.
    – James Love
    Aug 8, 2011 at 10:29
3

The CQWP layout can be changed to your needs by customizing the xsl the webpart uses. An explanation can be found here:

http://msdn.microsoft.com/en-us/library/bb447557.aspx

Some more background info can be found here: http://blogs.msdn.com/b/ecm/archive/2010/05/14/what-s-new-with-the-content-query-web-part.aspx

1
  • Thanks, Anita. I just tried make a change to the ItemStyle.xsl and save it, it gave a warning: Saving your changes will customize this page so that it is no longer based on the site definition. Do you want to continue? I'm worried about making changes that affect how files relate to the site definition, especially for upgrades and maintenance down the road.
    – Alex C
    Aug 7, 2011 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.