SharePoint 2007: Setting up a decent master page

There are two layers when styling up SharePoint – the master page layer, and the page layout layer. When you create a new page, the page is build on the “page layout” aspx file. Please note that an aspx file that defines the page layout does not need to be reference the masterpage – thus a masterpage doesn’t necessarily style all published pages in a website. Note that you cannot add webpartzones to the master page – if you do, you get the following error in SharePoint “Master pages cannot contain WebPartZones.”

Ok. So if i want to create a decent masterpage, I obviously want a decent css file behind it (ie not just basic text styling). Now, to create decent look and feel, your css file will normally reference images. The question is, where should these images be stored? I believe that the best place for the css file and related images is in subdirectory in the Style Library (http://localhost/Style%20Library/Forms/AllItems.aspx). As images in a css files are reference relative to the css file, and not the page calling the css file, you can easily reference images from the subdirectory (e.g background-image: url(testImage.gif);). Note – always use the browser to access the style library and add files – don’t try to look on the filesystem (only the standard SharePoint css files exist physically there). Also note that this structure also seems to also be followed by one of the first MOSS websites – http://www.hedkandi.com

Right – so here’s an outline of the procedure for applying a masterpage. Prior to the Sharepoint Beta 2 Tech Refresh, you can not apply masterpages to all site definitions. I have yet only tested this on a publishing site (see http://www.rnowik.com/blogpost/85/ for a list of site defs that permit masterpages to be applied).

  1. Create a masterpage (note that it needs to have several controls embedded in it, these are explained below and may only be relevant on a publishing website).
  2. Upload the masterpage, corresponding css file if relevant and any related images to the style library http://localhost/Style%20Library/Forms/AllItems.aspx. Note that masterpage galleries are central to SharePoint. These do not actually exist at a site level. Remember to publish and then approve.
  3. On the site that you want to apply the masterpage to, go to the then “Modify All Settings” page and click to go to the “Site Master Page Settings” page.
  4. Select the masterpage that you want to apply to the site, and if relevant select the associated css file (browse to this via the style library dialog).
  5. Click OK and the masterpage will be applied.

Note that you need to ensure that people browsing a masterpaged site, also have permissions to read the “Style Library”. If the site is to be part of an externally facing website, you will also want to set up anonymous access.

Stuff that (probably) needs to go in a masterpage
Note that i may be missing a call to an authorisation mechanism. I don’t think this is the case, but its probably worth confirming.
This should go at the top of the master page (prior to the “html” node of the html doc).

<%@ Master language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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="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" %>

The following needs to go within the “head” part of the html doc

 
<asp:ContentPlaceHolder id="PlaceHolderPageTitle" runat="server"/>
<SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/Stacked.css %>" runat="server"/>
<SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/controls.css %>" runat="server"/>
<SharePoint:ScriptLink language="javascript" name="core.js" runat="server" />
<SharePoint:ScriptLink language="javascript" name="ows.js" runat="server" />
<Sharepoint:CssLink runat="server" />
<asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server"/>

The following three lines need to appear in order in the body tag (i think)

 

<body onload="javascript:_spBodyOnLoadWrapper();">
<WebPartPages:SPWebPartManager runat="server" />
<form id="Form1" runat="server" onsubmit="return _spFormOnSubmitWrapper();">

The following can go anywhere within the remainder of the html doc (however note where authoring containers wrap).

<PublishingSiteAction:SiteActionMenu runat="server" />
<PublishingWebControls:AuthoringContainer id="authoringcontrols" runat="server">
    <SharePoint:DelegateControl ControlId="GlobalSiteLink1" Scope="Farm" runat="server"/>
</PublishingWebControls:AuthoringContainer>
<PublishingWebControls:AuthoringContainer id="authoringcontrols2" runat="server">
    <SharePoint:DelegateControl ControlId="GlobalSiteLink2" Scope="Farm" runat="server"/>
</PublishingWebControls:AuthoringContainer>
<PublishingWebControls:AuthoringContainer id="authoringcontrols3" runat="server">
    <wssuc:Welcome id="explitLogout" runat="server"/>
</PublishingWebControls:AuthoringContainer> <PublishingWebControls:AuthoringContainer id="authoringcontrols4" runat="server">     <PublishingConsole:Console runat="server" /> </PublishingWebControls:AuthoringContainer>
<asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea" runat="server" />
<asp:ContentPlaceHolder id="PlaceHolderMain" runat="server"/>

You May Also Like

About the Author: rnowik

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.