Goal
The main goal is to use a Custom List name "Sample" and use a Content Query Web Part to show it with custom design style.Process
- Create a custom list with name "Sample". The should just have 3 fields.
- Title - This is the main text to be shown for the picture.
- Picture - This is the hyperlink column for the picture of the item.
- Skills - This is a simple multiple line comment for the item.
- Go to any page. Add a web part. Drop a Content Query Web Part(CQWP) on the page from "Content Rollup".
- Click "Open tool pane".
- Content Query Tool Part > Query > Source > Show items from the following list: > Select "SAMPLE"
- Content Query Tool Part > Query > Presentation > Please see the picture as a default setting. I am going to leave it as it is.
- Click "Save" and the view of the web part will be a default text one which is going to look like picture below.
- On Clicking the picture it goes to the display record screen.
But now moving back to our goal. We need to show the data in a custom design layout. So follow the below given steps.
- Open a SharePoint 2010 designer.
- All Files > Style Library > XSL Style Sheets > ItemStyle.xsl(Edit it in advance mode)
- Find this element, copy it and paste it at the bottom of the XSL.
<xsl:template name="Default" match="*" mode="itemstyle">...</xsl:template>
- Change the name and match to Sample.
<xsl:template name="Sample" match="Row[@Style='Sample']" mode="itemstyle">...</xsl:template>
- Also if you edit the web part you can now see the item in the ItemStyle list. Make changes to map the correct fields too.
- Make the changes to the xsl(As you want the view of the list) or can copy the whole block and paste it at the bottom of the ItemStyle.xsl.
<xsl:template name="Sample" match="Row[@Style='Sample']" 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> <table cellpadding="0" cellspacing="5" border="0" style="border:1px Solid #efefef;width:400px;"> <tr> <td style="width:100px" align="center"> <a href="{$SafeLinkUrl}" title="{@LinkToolTip}"> <img class="image" src="{$SafeImageUrl}" title="{@ImageUrlAltText}" /> </a> </td> <td valign="top" align="left"><a href="{$SafeLinkUrl}" title="{@LinkToolTip}"> <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><br /><xsl:value-of select="@Description" disable-output-escaping="yes" /></td> </tr> </table> </xsl:template>
- Once you are done with that you can see the below given view on the screen.
- Thats it.
I have tried my best to keep this as simple as possible for freshers who are learning SharePoint.
Its works thanks
ReplyDeleteGreat!
DeleteGreat Post!!! Helped a lot
Deletehellow. ,
ReplyDeleteGreat Post.
please tell me a simple way . to get site url in itemstyle.xsl
thanks Maulik... this article very helpful for me.
ReplyDeleteVery helpful article, thanks very much! :-)
ReplyDeleteThank you for your post. When I try to use it in Sharepoint 2007, all item styles don't work properly. Please could you tell te if it is compatible with sharepoint 2007? Thank you.
ReplyDeleteNope so i mentioned SharePoint 2010. Sorry.
Delete