Using a custom master page in a site definition
Summary
Using a site definition in a SharePoint solution for a custom master page in SharePoint 2007
Method
UPDATE
Don't use the SharePoint Solution Generator, so far we have not been able to upgrade the site definitions through a solution without it killing existing sites based on the site definition.
I have seen many different ways of doing this, but I found the following method seemed to work for me, using the "SharePoint Extensions for Visual Studio 2005" and the "SharePoint Solutions Generator"
Open the Visual Studio Project
- Use the "SharePoint Solution Generator" to create a site definition project.
- Open the project and add your custom master page to the "Site Definition" folder
Edit the onet.xml file
- Open up "onet.xml"
- Add the following node to the "ListTemplates" section
<ListTemplate
Name=”mplib”
DisplayName=”$Resources:MasterPageGallery;”
Description=”$Resources:global_onet_mplib_desc;”
SetupPath=”global\lists\mplib”
Type=”116”
BaseType=”1”
Path=”GLOBAL”
Hidden=”TRUE”
HiddenList=”TRUE”
NoCrawl=”TRUE”
Unique=”TRUE”
Catalog=”TRUE”
OnQuickLaunch=”FALSE”
SecurityBits=”11”
AllowDeletion=”FALSE”
AllowEveryoneViewItems=”TRUE”
Image=”/_layouts/images/itdl.gif”
AlwaysIncludeContent=”TRUE”
DocumentTemplate=”100”
/>
Edit the Configuration node
- Add the "MasterUrl" attribute to the "Configuration" node with a value of "_catalogs/masterpage/project.master", where project.master is the name of your custom master page. This means all the pages using the "~masterurl/default.master" token will use the URL defined to point to your custom master page
<Configuration
ID=”0”
Name=”Default”
MasterUrl=”_catalogs/masterpage/project.master“
>
Add the Module Node
- Add a "Module" node to the Modules section of the configuration called "MasterPage" that will reference the module definition in the "Modules" section of the onet file
<Module Name=”MasterPage” />
- Add a module definition to the "Modules" section of the onet file. This will copy the custom master page file into the master page library when the site is provisioned.
<Module
Name=”MasterPage”
List=”116”
Url=”_catalogs/masterpage”
RootWebOnly=”FALSE“>
<File
Url=”project.master”
Type=”GhostableInLibrary”
IgnoreIfAlreadyExists=”TRUE”
/>
</Module>
Save and deploy the project
- Save the onet file and then deploy the project into your environment using the deploy option in "SharePoint Extensions for VS 2005"
- When you create a new site from your site definition it should now use your new master page.
Below is a screen grab of the onet.xml file with all the changes highlighted