Showing posts with label Content Query. Show all posts
Showing posts with label Content Query. Show all posts

Tuesday, December 11, 2012

PageQueryString in Content Query

PageQueryString allows to configure the Content Query Webpart dynamically using the query string in the url. Let's configure the CQWP to retrieve different categories of announcements based on the query string value.
Add a CQWP to the page and configure Query section as follows :
Source: Show items from all sites in this site collection
List Type: Announcements
Content Type:Show items of this content type group : My Content Types

Content Type:

Show items of this content type: Company

Announcements

In additional filters Select "Announcement Category" filed is equal to [PageQueryString : Category]

Save the webpart. I have placed the CQWP on the homepage of my site "http://intranet.contoso.com", so if I change the url to "http://intranet/SitePages/Home.aspx?Category=Technology", this is the result I get.

PageFieldValue is used to show the related content. Following examples illustrates it. Go to your list which contains our custom content type "Company Announcements". In the ribbon select List->Customize Form->Modify Form Webparts->Default Display Form 

Add CQWP and configure the webpart to use our custom content type. In Additional filters section select Announcement Category is equal to [PageFieldValue:Announcement Category] and  Title is not equal to [PageFieldValue:Title]

This will ensure that when we click on an item we will also get to see related items based on the Announcement Category of the current item and at the same current item will not be shown in the related announcements section.

Saturday, October 20, 2012

XSL Read More and Full Data Content Query

 

Edit in ItemStyle.xsl


  <xsl:template name="FullData" match="Row[@Style='FullData']" mode="itemstyle">
   <xsl:variable name="SafeLinkUrl">
                     <xsl:call-template name="OuterTemplate.GetSafeLink">
                           <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
                           <xsl:with-param name="UseFileName" select="1"/>
                     </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:value-of select="@Body" disable-output-escaping="yes"/>
<div align="right" style="color:black;">                  
  <input type="button" onclick="test('dsf');" value="Close"></input>  </div>

 

<SCRIPT language="JavaScript"><![CDATA[
            function test(avalue) {
               var url = location.search;
               var getIndex = url.indexOf("Source=");
               var getUrl=url.substring(getIndex,url.length).replace("Source=","");
window.location = decodeURIComponent(getUrl);
              
            }
      ]]></SCRIPT> 

       </xsl:template>

 
 
 
  <xsl:template name="ReadMore" match="Row[@Style='ReadMore']" mode="itemstyle">
 
 
   <xsl:variable name="SafeLinkUrl">
                     <xsl:call-template name="OuterTemplate.GetSafeLink">
                           <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
                           <xsl:with-param name="UseFileName" select="1"/>
                     </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:value-of select="concat(substring(@Body,0,500),'...')" disable-output-escaping="yes"/>
<div align="right" style="color:black">                     <a href="{$SafeLinkUrl}">Read more</a></div>
            

       </xsl:template>