SharePoint 2010 – Content Query Web Part – Open Links in new window

3 במאי 2011

Content Query Web Part is very useful Web Part that allow show relevant data from defferent sources


by definition special filter conditions.  But when relevant data is rendered all link are opened in the same window.


You can change this behavior by changing ItemStyle.xsl that placed in "Style Library" library inside "XSL Style Sheets"


folder. You can navigate to this library: http://servername/Style%20Library.


For changing ItemStyle.xsl file, download it to local disk.


For example if you use "Default" style inside Content Query Web Part, you can duplicate  xsl:template part with name


"Default"  and change style name for example "DefaultNewWindows". Inside this template you can add new attribute

"target" to "a" element with value "_blank", it will be seen so – <a href="{$SafeLinkUrl}" target="_blank">

 <xsl:template name="DefaultNewWindows" match="*" 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="SafeImageUrl">            <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">                <xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>            </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">            <xsl:if test="string-length($SafeImageUrl) != 0">                <div class="image-area-left">                     <a href="{$SafeLinkUrl}" target="_blank">                      <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>                      <img class="image" src="{$SafeImageUrl}" title="{@ImageUrlAltText}">                        <xsl:if test="$ImageWidth != "">                          <xsl:attribute name="width">                            <xsl:value-of select="$ImageWidth" />                          </xsl:attribute>                        </xsl:if>                        <xsl:if test="$ImageHeight != "">                          <xsl:attribute name="height">                            <xsl:value-of select="$ImageHeight" />                          </xsl:attribute>                        </xsl:if>                      </img>                    </a>                </div>            </xsl:if>            <div class="link-item">              <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>                <a href="{$SafeLinkUrl}" title="{@LinkToolTip}" target="_blank">                  <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 class="description">                    <xsl:value-of select="@Description" />                </div>            </div>        </div>    </xsl:template>


Save this ItemStyle.xsl file and upload it to the same "Style Library" library inside "XSL Style Sheets", check-in and publish


this file. After this you can choose new style inside Web Part Tool Part for "Content Query Web Part" as showed in picture


below inside "Presentation" Group.


 


After applying changes and saving your page, all link inside "Content Query Web Part" will be opened in new window.

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *