Wednesday, January 6, 2010

Passing custom arguments to the content query web part


We had a requirement to access the parameters entered by a content author/administrator in the tool pane of the content query web part (CQWP) to in the item style xslt template.
For this we decided to extend the functionality of the CQWP by sub-classing it. We included additional input fields to the tool pane by creating a new tool part class and added out custom tool part class to the out of the box tool pane of the CQWP.
To make the parameters entered in the tool part to be accessible in the ItemStyle.xsl we have to override the ModifyXsltArgumentList method of the CQWP.
protected override void ModifyXsltArgumentList(ArgumentClassWrapper argList)
{
base.ModifyXsltArgumentList(argList);
argList.AddParameter("yourparametername", "namespace", value);
}
Now the parameter can be accessed in the contentquerymain.xsl as a parameter.
<xsl:param name="cbq_isgrouping" />
<xsl:param name="cbq_columnwidth" />
<xsl:param name="Group" />
<xsl:param name="GroupType" />
<xsl:param name="cbq_iseditmode" />
<xsl:param name="cbq_viewemptytext" />
<xsl:param name="SiteId" />
<xsl:param name="WebUrl" />
<xsl:param name="PageId" />
<xsl:param name="WebPartId" />
<xsl:param name="FeedPageUrl" />
<xsl:param name="FeedEnabled" />
<xsl:param name="SiteUrl" />
<xsl:param name="BlankTitle" />
<xsl:param name="BlankGroup" />
<xsl:param name="UseCopyUtil" />
<xsl:param name="DataColumnTypes" />
<xsl:param name="ClientId" />
<xsl:param name="yourparametername" />
You can access the parameter now in the ItemStyle.xsl as follows:
<xsl:value-of select="$yourparametername"/>

No comments:

Post a Comment