Pages

Friday, August 31, 2012

SharePoint - Content Query Web Part open item in edit view

I like the CQWP and how you can load items from other locations. The default action behind an item that is shown by the CWQP is loading the display view. I really wanted to open the edit mode.  Thanks to the Internet and my colleague Marnix I figured it out!

You have to follow these instructions:

  • Open SharePoint Designer
  • Click at All Files
  • Click at Style Library
  • Click at XSL Style Sheets
  • Make a back-up of ContentQueryMain and ItemStyle
  • Check out ContentQueryMain and add the following code:

    <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>
  • Save and check in and publish
  • Check out ItemStyle and add the following code:
<xsl:template name="NameOfTheTemplate" match="Row[@Style=' NameOfTheTemplate']" mode="itemstyle">
        <xsl:variable name="SafeLinkUrl">
            <xsl:call-template name="OuterTemplate.GetEditLink">
                <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 bullet">
            <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
            <a onclick="javascript:SP.UI.ModalDialog.ShowPopupDialog('{$SafeLinkUrl}'); return false;" onmouseover="javascript:this.style.cursor='hand';" title="{@LinkToolTip}">
                        <xsl:value-of select="$DisplayTitle"/>
            </a>
        </div>
    </xsl:template> 

  • Save, Check in and Publish.
The last thing you have to do is edit the CQWP and use the itemstyle. That should do the trick!

I want to thank the author of this article:
http://www.aaune.org/wiki/index.php?title=CQWP_Direct_link_to_Editform


0 replies:

Post a Comment