240 likes | 420 Views
Content Query Web Part. Brendon Pilott Systems Administrator Gracelands Group of Services Twitter: @ brendonpilott E-mail: brendon@gracelands.org.nz. Blog List. Content Query. Document Library. Content Query. Custom List. Content Query. What is it?.
E N D
Content Query Web Part Brendon Pilott Systems Administrator Gracelands Group of Services Twitter: @brendonpilott E-mail: brendon@gracelands.org.nz
What is it? “Content Query is a Web Part that displays a dynamic set of items based on a query that you build by using a Web browser. You use the query to specify which items are displayed, and you can set presentation options to determine how those items are displayed on the finished page” - Microsoft
What does it do? • Display content from multiple lists and sites • Filter content so it is relevant • Dynamic view of content on a page • Most current content, refreshed on every page load • Can be styled with XSL and CSS
How does it work? • It builds a CAML (Collaborative Application Markup Language) query and uses the Microsoft.SharePoint.SPSiteDataQuery class to query the server • Presentation options are applied • Security trimmed • Content Query Web Part (CQWP) automatically displays new content
Extensible Stylesheet Language (XSL) • CQWP uses XSL files located in: • \Style Library\XSL Style Sheets\ • They parse the query results for display on the page • Do not edit the original XSL files • Create copies in a sub-folder, edit as necessary and modify the CQWP to use the new XSL files
Important XSL files • ContentQueryMain.xsl • Generates the appropriate calls to the Header and Item templates • ItemStyle.xsl • Contains templates that define how to display an item • Header.xsl • Contains templates that defines how to display a header
How are templates structured? • Each template starts with <xsl:template … … > • This defines the template name, the match string and the mode, and the template ends with </xsl:template> • Each template includes two sections: • <xsl:variable> processes the data and ensures correct formatting, especially used for images and links • <div> sections renders the HTML, includes the data, and applies styles from CSS classes
Issues and workarounds • Limited to 1000 lists – there is a workaround but be wary of the performance hit • Does not display items that are checked out or are not published or approved - workaround is to change the web part UseCache property to False • Does not work with anonymous access - workaround is to add two fields to the web part properties • If you want to filter on custom fields that are not in site columns then you may have to add the field names to the AdditionalFilterFields property
Issues and workarounds • It pulls from the database every column in your list even if you only need to display a few columns • This causes the query to take longer and moves a lot more data from the database server to the web front end • Solution: • When you use ViewFieldsOverride you can specify the columns you want to display and SharePoint won’t pull back all of the extra columns
Who can use it? • MOSS 2007 • SharePoint 2010 Standard and Enterprise • It is not available in WSS or Foundation because it needs the SharePoint Publishing Features
Key Feature - Filtering • Dynamic Filtering • If you want the filter to use data that is specific to a page • PageFieldValue • Dynamically replace the filter value with the current page’s field value • PageQueryString • Looks at the URL query string for a value to use in the Query
Demo • Enable publishing feature on the site collection and on the site • Add a CQWP to a page • Configure the CQWP – Query, Filter, Presentation • Create a new XSL Template and make it look good
Content Slide • 4th Annual Community SharePoint Conference • Business and Technical Tracks, all levels • Superb Internationally Renowned SharePoint Experts • EARLY BIRD DISCOUNT- $650.00 (full price $750.00) • Register NOW: www.sharepointconference.co.nz