Add Table of Contents to a Wiki page in SharePoint 2010

The content of wiki pages can get really long sometimes. My client has asked me to create a table of contents like the one that is used in Word documents to navigate to contents. This article online was quite helpful to get me started. In the article, the author added scripts to the wiki page layout. In my case, my client didn’t use publishing pages. So I added the scripts to web parts and then add the web parts to the content.

Note: This method is based on the use of H1, H2, H3, H4 tags. It wouldn’t work if there is no tags to the content.

Here are the steps:

1. Create a text file using Notepad, name it table_of_contents.txt. Copy the following code to the file

<!-- Table of Contents --> 
<div id="wiki-index"> 
<div class="toc">Table of Contents</div> 
<!-- Table of Contents -->
<script type="text/javascript"> 
var current = $(this);   
current.attr("id", "title" + i);   
$("#wiki-index").append(("<a id='link" + i + "' href='#title" +         
i + "' title='" + current.attr("class") + "'>" +         
current.html() + "</a>"));         
}) }); 
#wiki-index{border: 1px black dashed; 
background-color: whitesmoke; float: left; 
padding: 10px; padding-top: 0px; } 
#wiki-index .toc{font-size: 1.1em; 
font-weight: bold; text-align: center; 
padding: 5px; }
#wiki-index a[title=ms-rteElement-H1] 
{ font-size:14px; font-weight: bold} 
#wiki-index a[title=ms-rteElement-H2] 
{ font-size:12px; font-weight: normal} 
#wiki-index a[title=ms-rteElement-H2] div 
{ margin-left: 10px;} /*Add indent in front*/
#wiki-index a[title=ms-rteElement-H3] 
{ font-size:10px;} 
#wiki-index a[title=ms-rteElement-H3] div 
{ margin-left: 15px;} /*Add indent in front*/
#wiki-index a[title=ms-rteElement-H4] 
{ font-size:8px;} 
#wiki-index a[title=ms-rteElement-H4] div 
{ margin-left: 20px;} /*Add indent in front*/

The above code contains html, jQuery and CSS. The jQuery scripts append links of H1, H2, H3 and H4 text to the end of the Table of Contens.

2. Open the site collection in SharePoint Designer 2010. Import the text file to Site Assets or Style Library folder.

3. Right click on the text file, select “Properties”. Copy the location URL.

4. Go back to the browser. Edit the page and insert a Content Editor Web Part to the content area.

5. Edit the Content Editor Web Part and enter the URL copied in step 3 to the content link text box. Test the link, make sure it works.

6. Save the page. That’s it. You can export the above contnet editor web part and upload it to the web part gallery for reuse on other pages.


When user jumps to the very bottom of a wiki page, it may take a while to scroll back up. A back to top button might be useful in this case. Here’s how to add one. Note: The following steps need to work with the table of contents.

1. Create another text file using Notepad, name it top_button.txt. Copy the following code to the file

<div class="top_button">
<a href="#wiki-index">Back to Top</a>
/*Display the button to the right of the content*/ 
.top_button {  float:right; }

2. Open the site collection in SharePoint Designer 2010. Import the text file to Site Assets or Style Library folder or wherever you stored the table_of_contents.txt file above.

3. Follow step 3-6 in the first part of this article. Note: Need to move the web part to the bottom of a section or the page. You can have as many of this web part as needed.



Shorten field content in List Views in SharePoint Designer


I have a list called Introducing and the list has a column called Body. Body has a type of multiple lines of text.

One of the list views displays the Title and Body columns. There are entries that have a lot of content in the Body column. To make it look tidy and clear, we’d like to only display the first 200 characters of the content and use “…” to indicate more content.

Final result:


  1. Open up the site in SharePoint Designer.
  2. From the left Site Objects panel, select Lists and Libraries. In the middle of the page, choose the list that you want to manipulate.
  3. To make sure that I don’t mass up with other views, I created a new view in the Views pane called Short.
  4. Click on Short view to open it up.
  5. Optional step. (On the Option tab in the Ribbon, click Add/Remove Columns to choose the columns that you want to display in this view. )
  6. On the top Ribbon, click on the Home tab->Advanced Mode. Note: you need to be the site collection administrator to have this option enabled.
  7. Go to the Design tab->Customize XSLT->Customize Entire View
  8. Change the display to Split and click on the Body content, not the Title field. The code of the content should be highlighted in the editor. The code looks like this <xsl:value-of select=”$thisNode/@*[name()=current()/@Name]” disable-output-escaping=”yes”/>
  9. Replace the above code with: <xsl:value-of select=”substring($thisNode/@*[name()=current()/@Name], 1, 200)” disable-output-escaping=”yes”/><xsl:if test=”string-length($thisNode/@*[name()=current()/@Name]) &gt; 200″>…</xsl:if>
  10. Save the changes.
  11. Ctrl+F to bring up the Find and Replace window. Navigate to the Replace tab.
  12. In the Find what box, type in ddwrt:ghost=”hide”, replace it with empty string. Yes, we want to get rid of this. It prevents you from editing them.
  13. Save and see the view in the browser.

Helpful links:

Modify XsltListView in SharePoint designer not saving

sharepoint designer 2010 – custom xslt in blog/default.aspx not saving

Unable to display this Web Part error

Unable to display this Web Part

Search Site Custom Master Page and Default Master Pagge

Wasted my SharePoint Administrator half a day to debug something that was my fault. Sorry Dave!

The search site(Standard SharePoint) uses minimal.master as the Site master page(In SPD, choose Set As Custom Master Page) and uses v4.master as the System master page(In SPD, choose Set As Default Master Page)

To customize the master page on search site, make copy of minimal.master and DON’T change v4.master as the DEFAULT MASTER PAGE!!