Tuesday, January 24, 2012

More... link in Content Query Webpart

Following requirements achieved  using content query web part with combination for XSL style sheet
1. More link to navigate all items
2. Add New item link to add new item and should open in a dialog window
3. Each item has to be hyperlinked and should open in a dialog window
Snapshot of final output
clip_image001

Implementation Details
Achieved by creating custom XSL template, and associated to Content Query web part
We can reuse this template with minor changes. Hope this template will save your time while implementing these kind of solutions
<xsl:template name="moreArticles" match="Row[@Style='moreArticles']" 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>
<xsl:variable name="LinkTarget">
<xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>
</xsl:variable>
<div id="linkitem" class="item">
<xsl:if test="string-length($SafeImageUrl) != 0">
<div class="image-area-left">
<a href="{$SafeLinkUrl}" target="{$LinkTarget}">
<img class="image" src="{$SafeImageUrl}" alt="{@ImageUrlAltText}" />
</a>
</div>
</xsl:if>
<div class="item bullet link-item">
<xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
<!—following line of code for open item in dialog window-->
<a href="/departments/it/KnowledgeBase/_layouts/listform.aspx?PageType=4&amp;ListId={@ListId}&amp;ID={@ID}" onclick="EditLink2(this,ctx.ctxId);return false;" onfocus="OnLink(this)" target="_self">
<!--<a href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}">-->
<xsl:value-of select="$DisplayTitle"/>
</a>
<div class="description">
<xsl:value-of select="substring(@Description,1,200)" disable-output-escaping="yes" />
</div>
</div>
</div>
<xsl:if test="count(following-sibling::*)=0">
<div>
<!—following line of code for more link-->
<p align="right"><strong><a><xsl:attribute name="href">/departments/it/knowledgebase/pages/MoreArticles.aspx</xsl:attribute>More KB Articles...</a></strong></p>
<!—following line of code for Add New Item link-->
<p align="left"><img src="/PublishingImages/kbImages/addImg.png" alt=""/><strong><a><xsl:attribute name="onclick">javascript:NewItem2(event, &quot;/departments/it/knowledgebase/_layouts/listform.aspx?PageType=8&amp;ListId={8386e5d5-f918-4c9c-9e70-c39943dcbc70}&amp;RootFolder=&quot;);javascript:return false;</xsl:attribute> <xsl:attribute name="href">/departments/it/knowledgebase/_layouts/listform.aspx?PageType=8&amp;ListId={8386e5d5-f918-4c9c-9e70-c39943dcbc70}&amp;RootFolder=</xsl:attribute>Add New KB Article</a></strong></p>
</div>
</xsl:if>
</xsl:template>

2 comments: