0

I want to add an header and a footer to the data displayed by a Content Query wp using SharePoint Designer. I had been following the following tutorials: Link 1 and Link 2.

It works fine but the header and the footer only get displayed if there is at least one item in the webpart. I need to make them visible even if there are not any items to be shown.

Can anyone provide some guidance on how to do this or refer me to a tutorial?

1
  • You cannot do that in the ItemStyle because it renders the content of your list items and the div and css classes are in that .XSL. Try to add logic in the Header.xsl or ultimately in ContentQueryMain being very careful changing this one
    – Alvmad
    Oct 3, 2013 at 8:04

1 Answer 1

1

To add a header and/or footer to a CQWP, you need to change the styles in the ContentQueryMain.xsl, not the ItemStyle.xsl. It is not advisable, though, to change the original ItemStyle or ContentQueryMain files. Other CQWPs in the same site collection will also use these files and if you break them, you may break things in sites you don't own. Better, create copies of these XSL files and reference the CQWP to these copies.

These XSL files are not easy to understand if you are just starting with CQWP and/or XSLT. You may want to take this approach:

Make copies of ItemStyle.xsl and ContentQueryMain.xsl. You may want to put them in a sub-folder with a name that relates to the site or project. Create a CQWP in a page, export it to disk and edit it with Notepad. Edit the following rows and adjust the file names to your custom copies of the XSL files:

<property name=”ItemXslLink” type=”string”>/Style Library/custom/ItemStyle.xsl</property>
<property name=”MainXslLink” type=”string”>/Style Library/custom/ContentQueryMain.xsl</property>

Adjust the path and file name to reflect your custom copies of the xsl files. Save the webpart file in Notepad, then import the web part into the page again.

Now you can manipulate the custom copies of the XSL without affecting any other CQWPs on the site collection.

Dave Paylor has a good tutorial on his web site here:

http://paylord.wordpress.com/2012/09/28/cqwp-and-xslt-part-1/ http://paylord.wordpress.com/2013/06/12/cqwp-and-xslt-part-2/

Once you get the hang of that, you will be able to identify where in the ContentQueryMain you need to place your header and footer content.

5
  • This Procedure give Following Error. The web part references an untrusted XSL file. Only XSL files contained in this site's Style Library may be referenced. Oct 4, 2013 at 12:38
  • So, where is the custom XSL file? The error message really tells you where it needs to go, doesn't it?
    – teylyn
    Oct 4, 2013 at 22:32
  • It is in the Style Library named ContentQueryMainCopy(1).xsl Oct 5, 2013 at 6:51
  • It must be like this <property name=”ItemXslLink” type=”string”>sites/yourSite/Style Library/custom/ItemStyle.xsl</property> <property name=”MainXslLink” type=”string”>sites/yourSite/Style Library/custom/ContentQueryMain.xsl</property> Oct 9, 2013 at 9:08
  • I said above that you need to adjust the path to reflect your location of the files. That also includes the use of managed paths vs. root site collection!
    – teylyn
    Oct 13, 2013 at 9:43

Your Answer

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

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