Creating custom landing pages in SharePoint Part 1 - TheTable of Contents Webpart

The mission: Create a default landing page for each publishing site to aid in navigation.

The landing page should contain 2 sections.

  1. A section that lists all sites directly below the site you are on (1 level)
  2. A section that lists all the pages in the pages folder.
To pretty things up we may want to show images and/or descriptions for sites and pages.
The images and descriptions should be pulled from the image and description field the user enters when creating the new subsite or page.

Method No 1- Using the Table Of Contents Webpart

Note: Please read conclusion of this article to see why this solution didn't meet my requirements.

An obvious place to start is to see what we can do using the built in Web Part purpose built for our task.

The table of contents webpart provides a quick an easy method to display a Table of Contents. (Believe it or not)

It has cool features such as..

  1. Pick from which level to start the TOC
  2. Style your TOC 
  3. How many levels to show


More on the TOC web part can be found here and here

As we want this page to be a template with the contents starting from the current site we use SharePoint Designer.

Page templates reside in the same folder as Masterpages. 

_catalogs >  masterpage

  

To keep things seperated I have created 2 subfolders. Custom > Layouts and my new layout page is called WelcomeTOC.aspx.

I created this page by making a copy of one of the existing Welcome Pages.(I can't remember which but any layout will do)

I then added a TableOfContentsWebPart into the first WebpartZone. I'm not sure whether you need the ZoneTemplate tags.

<ZoneTemplate>
<PublishingWebControls:TableOfContentsWebPart runat="server" 
Description="" 
NoDefaultStyle="" 
AllowZoneChange="True" 
ViewContentTypeId="" 
AllowHide="True" 
ChromeType="None" 
UseSQLDataSourcePaging="True" 
AllowRemove="True" 
Dir="Default" 
AllowConnect="True" 
PageSize="-1" 
HelpMode="Modeless" 
Title="Table of Contents" 
PartOrder="1" 
ID="g_c8cdaea8_bb45_4983_afc7_bfcd74aa22dd" 
MissingAssembly="Cannot import this Web Part." 
FrameType="None" 
IsVisible="True" 
DetailLink="" 
ZoneID="TopColumnZone" 
ConnectionID="00000000-0000-0000-0000-000000000000" 
PartImageSmall="" 
PartImageLarge="" 
HelpLink="/_layouts/help.aspx" 
ShowWithSampleData="False" 
ExportMode="All" 
IsIncludedFilter="" 
HelpUrl="/_layouts/help.aspx" 
DataSourceID="" 
IsIncluded="True" 
ExportControlledProperties="True" 
FrameState="Normal" 
AllowEdit="True" 
AllowMinimize="True" 
SuppressWebPartChrome="False" 
AnchorLocation=""
__MarkupType="vsattributemarkup"
__WebPartId="{C8CDAEA8-BB45-4983-AFC7-BFCD74AA22DD}"
WebPart="true"
Height=""
Width=""
LevelsToShow="1"
DisplayColumns="2"
Level1Style="Vertical with descriptions">
<DataFields>
</DataFields>
<SampleData>
<Levels>
<Level LevelNumber="1" Path="/Site1" Title="Site 1" BeginColumn="true">
<Item LevelNumber="1" Path="/Page1" Title="Page 1" />
<Item LevelNumber="1" Path="/Page2" Title="Page 2" />
<Item LevelNumber="1" Path="/Page3" Title="Page 3" />
</Level>
<Level LevelNumber="1" Path="/Site2" Title="Site 2" BeginColumn="true">
<Item LevelNumber="1" Path="/Page1" Title="Page 1" />
<Item LevelNumber="1" Path="/Page2" Title="Page 2" />
<Item LevelNumber="1" Path="/Page3" Title="Page 3" />
</Level>
</Levels>
</SampleData><Xsl>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:cmswrt="http://schemas.microsoft.com/WebPart/v3/Publishing/runtime" exclude-result-prefixes="xsl cmswrt x"> 
<xsl:import href="/Style%20Library/XSL%20Style%20Sheets/Header.xsl" /> 
<xsl:import href="/Style%20Library/XSL%20Style%20Sheets/LevelStyle.xsl" /> 
<xsl:import href="/Style%20Library/XSL%20Style%20Sheets/TableOfContentsMain.xsl" /> </xsl:stylesheet></Xsl>
</PublishingWebControls:TableOfContentsWebPart>
</ZoneTemplate>

The important thing to note here is the

AnchorLocation="" attribute.
This sets the starting location of our links to the current site.
Customising the layout

Customising the layout is similar to customising the layout for other web parts such as the RSS reader or Custom Query web part. You need to do some XSLT.

You can edit 3 files

  • Header.xsl
  • LevelStyle.xsl
  • TableOfContentsMain.xsl

These files reside in Style Library > XSL Style Sheets

  

You can read more info here -

http://panvega.wordpress.com/2009/02/11/customizing-styles-of-table-of-contents-webpart-toc/#more-920

 

Conclusion

Basically you can alter the layout but the TOC web part is very limited as it only outputs the @Title, @Description, @LevelNumber and@Path.

This is OK if you just want some basic text but this won't cover our needs to display a possible image for each site or page listed.

A neat trick for verifying this is to add the following to your XSLT transformation in the LevelStyle.xsl file.

This will output the raw XML in between the <rawdata> tags.

That way you can see all the data you have to play with. I suspect this will work in the other xsl files in Sharepoint.

   <xsl:template name="ShowAll" match="Level[@LevelTemplate='ShowAll']">
  <rawdata>
    <xsl:copy-of select="*"/>
    </rawdata>
</xsl:template>

When you view the source of your page you will something like..

<rawdata>
<Item Description="I am happy to announce " LevelNumber="1" Path="/News/Pages/mypage.aspx" Title="Title of my page"></Item>
</rawdata>

Further reading:
Customizing Styles of Summary Links, Table of Contents, and Content Query Web Parts

Webcoda, SharePoint Consultants & Web Development

SharePoint Development Sydney is a crack team of SharePoint Consultants and SharePoint Developers.

We can't tell you their names or show their faces on TV but if you need a SharePoint job done right, call them on +61 2 9370 3602 or email us at info@sharepointsydney.com.au

Persecuted by the Government and shunned by society they developed their SharePoint skills in back streets and labor camps where other programmers wouldn't dare to tread. 

During a trek through the Himalayas they stumpled upon the fabled Mossy Yak who shared his SharePoint knowledge of how to attain Nirvana through a series of Workflows and Event Handlers. Their mission is to spread this knowledge through-out the world to bring peace, harmony and document version control to all .

 

Month List