Saturday, October 6, 2012

Adding Content to a SP 2010 Master Page

 

There are situations when we need some external content to be displayed in the master page, and at the same time allow users to easily update this content without much hassles of code-changes to the master page. I went hunting for the same and eventually identified a few of them. Here’s a compilation of what I felt beneficial to all. Let me know, if you have more on your list.

#1. You can create a user control and insert into the Master page footer. Click here for more details.

#2. You can insert the webpart directly into the Master page footer. Let’s see how.

<table cellpadding="0" cellspacing="0" width="875" align="left">
  <tr><td>
      <WebPartPages:ContentEditorWebPart AllowClose="true" AllowEdit="false" AllowHide="false"
                    AllowMinimize="false" AllowRemove="false" AllowZoneChange="false" ChromeType="None"
                    ContentLink="/Documents/Footer.htm" ID="vha_simple_footer" runat="server"
                    __WebPartId="{9AADFFEC-FA65-4BB7-BAE6-4DA3A85A56A0}" WebPart="true"></WebPartPages:ContentEditorWebPart>
   </td></tr>
  </table>

#3. In case your site pages are all based upon few Page Layouts, you “might” place some ContentPlaceHolders on these page-layouts, and then add the footer code into a content editor web part on a page that is based upon the Page Layout. Refer this article from Bamboo Solutions for a complete details on creating a custom page layout for a Publishing Site using Visual Studio 2010

#4. You may also use “Reusable Content” in SP Publishing HTML fields to achieve the same. Find here.

#5. Then there are IFrames, the old ways of displaying a web page content. Well, I know, most of us would start a discussion around the SEO, when we talk about IFrames on the pages. But it still works and provides another way to get external content into a master page. (Although, I personally know, how powerful iframes programing can be. Check here.)

This is how to get this in place. Insert the below piece of code, in the footer section of the master page:

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr><td>
       <iframe src="/Documents/Footer.htm" scrolling="no" frameborder="0">[Your browser does not support frames or is currently configured not to display frames. Please use an up-to-date browser that is capable of displaying frames.]</iframe>
</td></tr></table>

Next, upload the “Footer.htm” file with appropriate code in the [Documents] document library of the root site. I have a sample code for this file as:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head></head>
<body>
<div align="center"><span style="font-size:10pt">External footer content example</span></div>  </body>
</html>

I agree, this one is not the best of the practices, and I would advice not to consider this as a first hand solutions when other options might be more suitable for similar scenarios.

No comments: