330 likes | 443 Views
Code Camp NZ 2011. # CCNZ. www.mscommunities.co.nz. Customising Content Query Web Part (CQWP) in SharePoint 2010. Chakkaradeep ( Chaks ) Chandran SharePoint Consultant Microsoft New Zealand chaksc@microsoft.com http://www.chakkaradeep.com http ://blogs.msdn.com/chaks @ chakkaradeep.
E N D
Code Camp NZ 2011 #CCNZ www.mscommunities.co.nz
CustomisingContent Query Web Part (CQWP) in SharePoint 2010 Chakkaradeep (Chaks) Chandran SharePoint Consultant Microsoft New Zealand chaksc@microsoft.com http://www.chakkaradeep.com http://blogs.msdn.com/chaks @chakkaradeep
Session Objectives and Takeaways This session does not cover: • DataView Web Parts • Extending CQWP (C# Coding) • SharePoint Designer 2010 This session covers: • CQWP Basics • Anatomy of CQWP • CQWP Properties • Customizing CQWP • Tips & Tricks • CQWP in WCM • More Demos….
What is CQWP? • Displays a dynamic view of content on a page • CQWP can be configured to retrieve items from: • Single or Multiple List(s) • Single site or Sub-sites • Entire site collection
What is CQWP? • Centralize the content in the presentation layer • Ability to Filter, Sort, Order and Group results (Content Rollup) • Used in: • Content Management • Publishing • Content Delivery Scenarios
Using CQWP – Getting Started • Requires Publishing Features to be activated
Anatomy of CQWP • CQWP uses property settings and CAML to construct the query • Few available through tool pane • More advanced properties available and requires modifying the web part file • Once modified, you can re-import or even upload the modified file to the web part gallery • SPSiteDataQuery class to query the SharePoint site to gather results
ContentQueryMain.XSL • Receives all the content, parses it, and sends appropriate pieces to the ItemStyle and Header templates. • Maintains the structure of the Content By Query Web Part. • Stores data retrieved when querying content in the path /dsQueryResponse/Rows/Row.
ItemStyle.XSL • Contains templates that define how to display an item. • These templates receive and process one row of data at a time, ensuring that the style and data in the item rows is consistent.
Item Styles <xsl:template name="TitleOnly" match="Row[@Style='TitleOnly']" 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="@Title"/> <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/> </xsl:call-template> </xsl:variable> <div class="item link-item"> <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/> <a href="{$SafeLinkUrl}" title="{@LinkToolTip}"> <xsl:if test="$ItemsHaveStreams = 'True'"> <xsl:attribute name="onclick"> <xsl:value-of select="@OnClickForWebRendering"/> </xsl:attribute> </xsl:if> <xsl:if test="$ItemsHaveStreams != 'True' and @OpenInNewWindow = 'True'"> <xsl:attribute name="onclick"> <xsl:value-of disable-output-escaping="yes" select="$OnClickTargetAttribute"/> </xsl:attribute> </xsl:if> <xsl:value-of select="$DisplayTitle"/> </a> </div> </xsl:template>
demo Custom ItemStyles
Slots • Depending on the scope of your query, select one or more site or list columns • Column from a particular group – Column [Group]
Additional Filters – “context of the current article” • PageFieldValue • Dynamically replaces the value for the filter with the current page’s field value. • PageQueryString • Looks at the URL query string for a value to use in the Query. Courtesy: http://blogs.msdn.com/ecm
Before you start Getting the most out of this web part requires consideration and planning of your content management needs up front
demo Custom Styles
Styles Summary ContentQueryMain.xsl ItemStyle.xsl
Demo Summary • Customising default Style • FixedImage • Customising ContentQueryMain.xsl • Customising ItemStyle.xsl • Custom HTML rendering code
Tips and Tricks • Use consistent site columns for content filtering. • ALL XML inside a <property/> tag must be enclosed in a <![CDATA[ ]]> block. • Upload to the web part gallery a pre-configured CQWP. • Expose custom fields via AdditionalFilterFieldsto allow for modification via browser
Tips and Tricks • Use ListsOverride property to query against other list types • If you need to query against >1000 lists you can add the MaxListLimitattribute to the ListsOverrideproperty. • By default this is set to 1000 • There is a performance trade-off here • The CAML query can have any number of filter fields and values (tool pane is limited to three)
Tips and Tricks • Only list templates available at the site root are enumerated. • When setting properties requiring use of the column’s internal name remember a space is represented as _x0020_ : <property name="CommonViewFields" type="string"> Project_x0020_Title, Text;Project_x0020_Owner, Text;ProjectNotes, Text</property>
Tips and Tricks • When filtering on Yes/No data type use the value “1” and “0” • To render HTML and not raw tags set the disable-output-escaping attribute to true: <xsl:value-of select="@InternalName" disable-output-escaping="yes"/>
Thanks to our sponsors and partners! Sponsor Premier Partners Associated Partners Supporting Partners