How to: Change the display of items in a CQWP

If you’re using a content query web part to display list items on a page, you will have to change the .xsl files that the content query web part uses in case you want to change the display.
The ItemStyle.xsl file in the “Style Library/XSL Style Sheets” library folder will format the display of the Content Query contents.
The ContentQueryMain.xsl formats the values that the ItemStyle.xsl only displays.

In the ContentQueryMain.xsl you will have to get a variable to store the URL to the EditForm of the list item.
You do that by adding the following in the template:

<xsl:template name=”OuterTemplate.GetEditLink”>
<xsl:param name=”UrlColumnName”/>
<xsl:if test=”$UseCopyUtil = ‘True'”>
<xsl:value-of select=”concat($RootSiteRef,’/_layouts/CopyUtil.aspx?Use=id&amp;Action=editform&amp;ItemId=’,@ID,’&amp;ListId=’,@ListId,’&amp;WebId=’,@WebId,’&amp;SiteId=’,$SiteId,’&amp;Source=’,$Source)”/>
</xsl:if>
<xsl:if test=”$UseCopyUtil != ‘True'”>
<xsl:call-template name=”OuterTemplate.GetSafeStaticUrl”>
<xsl:with-param name=”UrlColumnName” select=”$UrlColumnName”/>
</xsl:call-template>
</xsl:if>
</xsl:template>

What this does is, it builds a URL that points to the edit form of the list item.
This is based on the GetSafeLink that is already in the .xsl file (which is the following):

<xsl:template name=”OuterTemplate.GetSafeLink”>
<xsl:param name=”UrlColumnName”/>
<xsl:if test=”$UseCopyUtil = ‘True'”>
<xsl:value-of select=”concat($RootSiteRef,’/_layouts/CopyUtil.aspx?Use=id&amp;Action=dispform&amp;ItemId=’,@ID,’&amp;ListId=’,@ListId,’&amp;WebId=’,@WebId,’&amp;SiteId=’,$SiteId,’&amp;Source=’,$Source)”/>
</xsl:if>
<xsl:if test=”$UseCopyUtil != ‘True'”>
<xsl:call-template name=”OuterTemplate.GetSafeStaticUrl”>
<xsl:with-param name=”UrlColumnName” select=”$UrlColumnName”/>
</xsl:call-template>
</xsl:if>
</xsl:template>

You can add the ‘OuterTemplate.GetEditLink’ template before or after the existing GetSafeLink.

Now that the template has been added, you will need to get the value from it into a variable and then use that variable with your anchor link to navigate to it.
Open up the ItemStyle.xsl file.
You need to add the following:

<xsl:variable name=”SafeLinkEditUrl”>
<xsl:call-template name=”OuterTemplate.GetEditLink”>
<xsl:with-param name=”UrlColumnName” select=”‘LinkUrl'”/>
</xsl:call-template>
</xsl:variable>

Be careful to add the variable in the correct template. You can see what is the template that you need to manipulate by following the steps here.
Once you have added the above, you will have a variable called SafeLinkEditUrl that you can then use in your anchor link to navigate to the EditForm of the list item; instead of the DispForm, which is the default behaviour.
If you followed the guidelines to have a modal dialog box displaying the page instead of navigating away from the current page (as explained here)
the following code will make sense.

<a onclick=”ShowPopupDialog(GetGotoLinkUrl(this));return false;”>
<xsl:attribute name=”href”>
<xsl:value-of select=”$SafeLinkEditUrl” />
</xsl:attribute>
<xsl:attribute name=”title”>
<xsl:value-of select=”@LinkToolTip” />
</xsl:attribute>
<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:text>PRO</xsl:text><xsl:value-of select=’substring(substring-after($ActualLinkUrl, “/PRO”), 1, 4)’/>
<xsl:text>: </xsl:text><xsl:value-of select=”$DisplayTitle”/>
</a>

If not, you can search for:

<a href=”{$SafeLinkUrl}” and change the SafeLinkUrl to SafeLinkEditUrl.

MGR: the Intelogist

About MGR: the Intelogist

SharePoint Server developer, turned Sitefinity developer, turned Angular developer, turned SharePoint Online consultant, turned Unily consultant, turned O365 consultant... Never a dull moment!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

This site uses Akismet to reduce spam. Learn how your comment data is processed.