Click to Rate and Give Feedback
MSDN
MSDN Library
Office Development
SDK Documentation
General Reference
 How to: Create a Minimal Master Pag...

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
How to: Create a Minimal Master Page

One of the first tasks that you must complete when configuring a Microsoft Office SharePoint Server 2007 Web site is to create one or more master pages. A master page contains references to elements that you can share across multiple pages in an Office SharePoint Server 2007 site, such as navigation, search controls, logon controls, and banner images. A master page can also contain the cascading style sheet (CSS) and ECMAScript (JScript, JavaScript) references that define the overall look and feel of your site. Commonly, every site—and therefore every page—in your site collection uses the same master page to present a consistent user experience across the entire site collection. Depending on your needs, you can use a different master page for one or for all of the sites in your site hierarchy to distinguish the various areas of your portal.

Master Page Galleries

When you provision a site collection in Office SharePoint Server 2007, the system creates a master page gallery that contains all the master pages and page layouts for that site collection. If the site collection uses either the Publishing Portal or Collaboration Portal templates, the master page gallery includes several master pages that are provided with Office SharePoint Server 2007, such as BlueBand.master. These master pages are located in the path C:\Program%20Files\Common%20Files\Microsoft%20Shared\web%20server%20extensions\12\TEMPLATE\FEATURES\PublishingLayouts\MasterPages\, with other example .master pages. You can use any of these master pages as they are, or you can customize them fully to create unique branding for your site.

Why Start with a Minimal Master Page

Creating and completing a master page to begin your SharePoint site customization takes planning and time. If you can, you want to prevent having to rewrite or back out code you don't need in your master page. This topic shows you how to create a minimal master page that includes only the minimal functionality that Office SharePoint Server 2007 requires so that you have a stable platform upon which to build your own master pages. Creating a minimal master page can help you avoid the time-consuming process of backing code out of a pre-existing .master page such as BlueBand.master, or removing functionality and then building it back in when your customization needs change again.

NoteNote:

This topic supports using the Minimal Master Page described as a Site Master Page in Office SharePoint Server 2007. It does not support using the Minimal Master Page described in this topic as a System Master Page in Office SharePoint Server 2007. Using this content with Windows SharePoint Services 3.0 is not explicitly supported.

You can, of course, create a master page from scratch. However, we generally do not recommend this because a truly empty master page does not include all the content placeholders that the Office SharePoint Server 2007 page model needs to work correctly.

The sample code in the following procedure includes only what the Office SharePoint Server 2007 page model requires—necessary content placeholders and controls to work with the page layouts that are included in a default Office SharePoint Server 2007 installation. Office SharePoint Server 2007 requires a master page that includes a title, branding, logon functionality, search functionality, breadcrumb functionality, and basic structural elements such as page areas, separators, borders, consoles, and description placeholders.

The following procedure uses Office SharePoint Designer 2007 as the master page design environment. You can, however, use a text editor, a Web editor such as Microsoft Office SharePoint Designer 2007, or an integrated development environment (IDE) such as Microsoft Visual Studio 2005 to create a master page.

The master pages included with Office SharePoint Server 2007 are based on the SPWeb.CustomMasterUrl property of the SPWeb class in Windows SharePoint Services.

To create a minimal master page

  1. Open SharePoint Designer.

  2. On the File menu, click New, point to SharePoint Content, and then click the Page tab.

  3. Double-click Master Page to create a new master page.

  4. Click Design to show the master page in design view. You should see header and left margin areas and several content placeholders in the master page.

  5. Click Code to show the master page in code view.

  6. Copy the following code into the master page.

    Xml
    <%-- Identifies this page as a .master page written in Microsoft Visual C# and registers tag prefixes, namespaces, assemblies, and controls. --%>
    <%@ Master language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Welcome.ascx" %>
    <%@ Register TagPrefix="wssuc" TagName="DesignModeConsole" src="~/_controltemplates/DesignModeConsole.ascx" %>
    <%@ Register TagPrefix="PublishingVariations" TagName="VariationsLabelMenu" src="~/_controltemplates/VariationsLabelMenu.ascx" %>
    <%@ Register Tagprefix="PublishingConsole" TagName="Console" src="~/_controltemplates/PublishingConsole.ascx" %>
    <%@ Register TagPrefix="PublishingSiteAction" TagName="SiteActionMenu" src="~/_controltemplates/PublishingActionMenu.ascx" %>
    <%-- Uses the Microsoft Office namespace and schema. --%>
    <html>
      <WebPartPages:SPWebPartManager runat="server"/>
      <SharePoint:RobotsMetaTag runat="server"/>
    
      <%-- The head section includes a content placeholder for the page title and links to CSS and ECMAScript (JScript, JavaScript) files that run on the server. --%>
      <head runat="server">
        <asp:ContentPlaceHolder runat="server" id="head">
          <title>
            <asp:ContentPlaceHolder id="PlaceHolderPageTitle" runat="server" />
          </title>
        </asp:ContentPlaceHolder>
        <Sharepoint:CssLink runat="server"/>
        <asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server" />
      </head>
      
      <%-- When loading the body of the .master page, SharePoint Server 2007 also loads the SpBodyOnLoadWrapper class. This class handles .js calls for the master page. --%>
      <body onload="javascript:_spBodyOnLoadWrapper();">
        <%-- The SPWebPartManager manages all of the Web part controls, functionality, and events that occur on a Web page. --%>
        <form runat="server" onsubmit="return _spFormOnSubmitWrapper();">
          <wssuc:Welcome id="explitLogout" runat="server"/>
          <PublishingSiteAction:SiteActionMenu runat="server"/>  
          <PublishingWebControls:AuthoringContainer id="authoringcontrols" runat="server">
            <PublishingConsole:Console runat="server" />
          </PublishingWebControls:AuthoringContainer>
          <%-- The PlaceHolderMain content placeholder defines where to place the page content for all the content from the page layout. The page layout can overwrite any content placeholder from the master page. Example: The PlaceHolderLeftNavBar can overwrite the left navigation bar. --%>
          <asp:ContentPlaceHolder id="PlaceHolderMain" runat="server" />
            <asp:Panel visible="false" runat="server">
            <%-- These ContentPlaceHolders ensure all default SharePoint Server pages render with this master page. If the system master page is set to any default master page, the only content placeholders required are those that are overridden by your page layouts. --%>
    <asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderTitleBreadcrumb" runat="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea"  runat="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderLeftNavBar" runat="server"/>
    <asp:ContentPlaceHolder ID="PlaceHolderPageImage" runat="server"/>
    <asp:ContentPlaceHolder ID="PlaceHolderBodyLeftBorder" runat="server"/>
    <asp:ContentPlaceHolder ID="PlaceHolderNavSpacer" runat="server"/>
    <asp:ContentPlaceHolder ID="PlaceHolderTitleLeftBorder" runat="server"/>
    <asp:ContentPlaceHolder ID="PlaceHolderTitleAreaSeparator" runat="server"/>
    <asp:ContentPlaceHolder ID="PlaceHolderMiniConsole" runat="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderCalendarNavigator" runat ="server" />
    <asp:ContentPlaceHolder id="PlaceHolderLeftActions" runat ="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderPageDescription" runat ="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderBodyAreaClass" runat ="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderTitleAreaClass" runat ="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderBodyRightMargin" runat="server" />
    </asp:Panel>
        </form>
      </body>
    </html>
    
  7. On the File menu, click Save As, provide a unique file name with the .master extension, and then save the file to the master page gallery (/_catalogs/masterpage) in your site collection.

See Also

Community Content   What is Community Content?
Add new content RSS  Annotations
Missing ending ContentPlaceHolder      Ithael   |   Edit   |   Show History
This sample, FYI, is missing a </asp:ContentPlaceHolder>, which should be placed right before the </form> tag. This end tag corresponds to the ContentPlaceHolder with the id "PlaceHolderMain".
PlaceHolderBodyRightMargin required for Web Part Page layout.      Ithael ... Thomas Lee   |   Edit   |   Show History
The default Web Part Page layout that ships with MOSS2007 also requires the PlaceHolderBodyRightMargin content placeholder: <asp:ContentPlaceHolder id="PlaceHolderBodyRightMargin" runat="server" />.
PlaceHolderTitleRightMargin required for edit item pages      arriba   |   Edit   |   Show History
The default system generated list creating/editing pages that come with SharePoint 2007 (such as NewForm.aspx or DispForm.aspx) also require the PlaceHolderTitleRightMargin content placeholder: <asp:ContentPlaceHolder id="PlaceHolderTitleRightMargin" runat="server"/>, which as of 30 April 07 isn't in the above.
Tags What's this?: Add a tag
Flag as ContentBug
[MSFT] Minimal Master Page not supported for use as a System Master Page      ldemaris   |   Edit   |   Show History

arriba -

You are correct. However, the pages you described are System pages, and therefore use the master page specified in Site Master Page Settings as the "System Master Page". We do not support using the Minimal Master Page provided in this article as a System Master Page - we only support it as a Site Master page. I realize that this was not called out explicitly in the article, and I apologize for any inconvenience.

Lincoln DeMaris [MSFT]

Tags What's this?: Add a tag
Flag as ContentBug
Minimal Master Page for WSS 3.0?      jacksbackw ... Thomas Lee   |   Edit   |   Show History
Unfortunately this does not work for those of us running WSS 3.0 not empowered with MOSS . Is there another Minimal Master Page code example for non MOSS situations?
Cannot Edit Web Parts With Minimal Master Page Code      drigfx   |   Edit   |   Show History
This code was helpful, thanks. But it seems one (at least I) cannot edit web parts in web part pages when applying this master.
Tags What's this?: Add a tag
Flag as ContentBug
RE: Cannot Edit Web Parts With Minimal Master Page Code      Sushant Bhatia   |   Edit   |   Show History
I cannot get the buttons on the edit panel of a web part to postback either. Has anyone run into this? Thanks.
RE: Cannot Edit Web Parts With Minimal Master Page Code      GiraffeOnFire   |   Edit   |   Show History
Have you made sure there are web part zones? That worked for me.
Tags What's this?: Add a tag
Flag as ContentBug
Useful Resource      AndyPoots   |   Edit   |   Show History

On this subject, Chapter 6 in book Real World SharePoint 2007 focuses on Customising and Branding the SharePoint 2007 Interface. ISBN: 978-0-470-16835-6

Well written book, and very useful for this very difficult area of SharePoint.

Heather Soloman's website is also really useful: http://www.heathersolomon.com/blog/

Tags What's this?: Add a tag
Flag as ContentBug
Another Useful Resource      The Moss Man ... Thomas Lee   |   Edit   |   Show History
There is also a good design blog @ http://www.thesug.org/blogs/kyles/default.aspx
I couldn't find 'SharePoint Content'      Michael Z.   |   Edit   |   Show History

On the File menu, click New, point to SharePoint Content, and then click the Page tab.?

I am using sharepoint designer 2007 trial version, when I do File->New, there is no 'SharePoint Content', different version of designer?

Tags What's this?: Add a tag
Flag as ContentBug
Re: I couldn't find 'SharePoint Content'      PANoone   |   Edit   |   Show History
Hi Michael,

The content does not reside on the local machine a la Dreamweaver but comes directly from the server and is only available upon connecting to a site.

This avoids messy business like multiple copies of files and synchronisation issues.
Tags What's this?: Add a tag
Flag as ContentBug
Re: Missing ending ContentPlaceHolder      PANoone   |   Edit   |   Show History
Ithael, the ContentPlaceHolder tag for "PlaceHoldermain" is self closing in the example.

<asp:ContentPlaceHolder id="PlaceHolderMain" runat="server" />

Did you actually receive a syntax error when using this template code?
Tags What's this?: Add a tag
Flag as ContentBug
Search Centre with Tabs requires PlaceHolderTitleBreadcrumb      Rick Mason   |   Edit   |   Show History
If you're using the "Search Centre with Tabs" site definition you need the "PlaceHolderTitleBreadcrumb" placeholder to be visible. It contains the search box and the tabs. (Not the breadcrumb trail - sounds like a bit of a hack.)
Flag as ContentBug
Has the code in the article been updated?      Frank Bonetto ... Thomas Lee   |   Edit   |   Show History
I want to start with a minimal page but I want to be sure before I can continue messing around with master pages.
Flag as ContentBug
How do I make my Custom Theme work with this?      Karthik Murugesan   |   Edit   |   Show History
I have a custom theme that changes the look and feel of Site Action button and Welcome text, when I change the site theme from default to the custom theme, I see no effect. Am I missing something? Please help me understand. Thanks, Karthik.
Tags What's this?: Add a tag
Flag as ContentBug
Useful Resource      Jamal From Persia Sharepoint Solution ... kamalakar   |   Edit   |   Show History

I usage this artcle to create a master page in Dubai Iranian Hospital site. It's very useful for me and I recommend to every one to using it. Also I translate this article to persian language in my blog .
http://www.sharepointsolutions.ir/blogs/jamal/Lists/Posts/Post.aspx?ID=44

Best regard
Jamal From Persia Sharepoint Solutions

Tags What's this?: great (x) Add a tag
Flag as ContentBug
MSO_ContentDiv required for minimal master!      jendxb   |   Edit   |   Show History

drigfx, Sushant Bhatia,

you need to use MSO_ContentDiv to make the toolpane for modifying web parts show up properly.

...as mentioned here: http://blogs.msdn.com/ecm/archive/2006/09/21/764759.aspx

- Positioning the toolpane
Find the <div> in your master page that wraps the content area of the page. On the OOB master page it is has the class "mainContainer" and contains the placeholders PlaceHolderPageTitleInTitleArea and PlaceHolderMain. Add the id “MSO_ContentDiv" and the runat="server" attribute such as:
<div class="mainContainer" id="MSO_ContentDiv" runat="server">
This will tell the Web part toolpane to position itself directly to the right side of that content area, where it is most usable, similar to the SharePoint default master page.

jennifer www.finalcandidate.com

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker