Create a Feature: Add Custom Master Pages to your Site Collections
- Navigate to the Features directory on your web server:
Local Drive:\Program Files\Common
Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES - Locate the PublishingLayouts Feature directory.
Copy this folder and paste it at the root of Features.
Rename the folder to a unique name of your choice. For my example I
used CustomMasterPages.
- Open your new Feature directory. At this point you can leave all the
default folders, or you can choose to clear out what you don't want to use.
You only have to keep Feature.xml and
ProvisionedFiles.xml. To create a clean file set, at a minimum
clear out the contents of each sub folder in the directory (en-us (or your
language), Images, MasterPages, PageLayouts, Styles).
- To start, we need at least one master page file in the Feature folder.
You can copy one of the existing master pages, paste the copy in the
directory, and rename the copy to your unique name, or alternately paste
in your custom master page, or create a new blank file with the extension of
.master.
Tip! To just get a master page going,
copy the sample code
from this
article and paste it in your custom master page file. That will
get you up and running for this article and give you a good starting point
for your customizations once the master page has been applied to your site.
If you do this, after pasting the code into your master page file, locate
this line of code and add a missing quotation mark:
<asp:ContentPlaceHolder id="PlaceHolderTitleBreadcrumb"
runat="server"/>
- Next, open the ProvisionedFiles.xml file in Notepad or a similar
editing application.
Local Drive:\Program Files\Common
Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\YourFeature - We are going to delete out all of the content and only keep the
OSGMasterPages Module tag and the
PublishingLayoutsPreviewImages Module tag.
As opposed to listing out what to strip out, here is the code you need in
this file:
<!-- _lcid="1033"
_version="12.0.4407" _dal="1" -->
<!-- _LocalBinding -->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="OSGMasterPages" Url="_catalogs/masterpage" Path="MasterPages"
RootWebOnly="TRUE">
<File Url="Sample.master" Type="GhostableInLibrary">
<Property Name="ContentType" Value="My Sample Master
Page" />
<Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview
Images/sample.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview
Images/sample.png" />
<Property Name="MasterPageDescription" Value="This is
my sample master page for use with collaboration or publishing sites."
/>
</File>
</Module>
<Module Name="PublishingLayoutsPreviewImages" Url="_catalogs/masterpage"
IncludeFolders="??-??" Path="" RootWebOnly="TRUE">
<File Url="Sample.png" Name="Preview Images/Sample.png"
Type="GhostableInLibrary">
</File>
</Module>
</Elements> - Update the properties to reflect the new master page details:
- Change the URL to your custom master page.:
<File Url="Sample.master" Type="GhostableInLibrary"> - Change the Preview Images to a custom image:
<Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview
Images/Sample.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview
Images/Sample.png" />
Add the custom image to the following directory:
Local Drive:\Program Files\Common
Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\PublishingLayouts\en-us - Update the Description. Enter a description for
your master page:
<Property Name="MasterPageDescription" Value="This is
my sample master page for use with collaboration or publishing sites."
/> - Update the image names:
<File Url="Sample.png" Name="Preview Images/Sample.png"
Type="GhostableInLibrary">
- Change the URL to your custom master page.:
- Save the ProvisionedFiles.xml file.
- Create a preview image in the language folder (in this case,
en-us).
- Next, open the Feature.xml file in Notepad or a similar
editing application.
Local Drive:\Program Files\Common
Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\YourFeature - There are four things you need to edit in this file:
- Change the Feature ID to a unique GUID. You
can generate GUIDs in Visual Studio (Tools - Create GUID - Registry
Format - Copy). Paste the new GUID for the ID and remove the curly
brackets.
<Feature Id="FDFCD4C4-F0D9-43b5-8739-A33681049657" - Update the title:
Title="Custom Master Pages" - Update the description:
Description="Custom master
pages for use across multiple site collections." - Change the Hidden state to False:
Hidden="False"
- Change the Feature ID to a unique GUID. You
- Save the Feature.xml file.
- Recycle the Application Pool for the site you plan to install the
Feature on, or reset IIS (Command Prompt - IISRESET).
- You are now ready to install the new Feature on the web server. Open a
Command Prompt and enter the following:- Change directories to the BIN folder in the
12 hive so you can use STSADM.exe:
cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12BIN - Launch STSADM and install the feature:
stsadm -o installfeature -name YourFeatureDirectoryName
Tip! To access STSADM quicker, refer to
Andrew Connell's SharePoint Developer Tip.
- Change directories to the BIN folder in the
- Now we will activate the feature on the site.
- Open your site and navigate to the Site Collection Features settings
page. Site Actions - Site Settings -
Modify All Site Settings -
Site Collection Features (under the Site Collection
Administration submenu). - The new feature will be listed:
- Select Activate.
- Open your site and navigate to the Site Collection Features settings
- The master pages are now ready to use on the site. Navigate to the
Master Page settings by selecting Site Settings in the
breadcrumbs and choosing Master Page. (Or Site Actions -
Site Settings -
Modify All Site Settings -
Master page (under the Look and Feel submenu). - Depending on your requirements, in either or both the Site
Master Page setting and the System Master Page setting, select your drop down box and choose your custom master page.
- Select OK.
- The master page is applied to the site. Note that I manually
added the "Sample Master Page" text to the Sample.master file. It will not
appear on yours by default.
Adding to our Feature: Adding More Custom Master Pages to your Feature
If you ever need to add new master pages to this feature, you can edit the
Feature and redeploy it. Alternately, you can create a new Feature for
each custom master page. For that scenario, just follow the steps above for
creating a new feature. The following outlines how to update your Feature with
new master pages.
- Navigate to your custom master page Feature directory and add the
appropriate files for your new master pages. - Navigate to and open the ProvisionedFiles.xml file.
Add a FILE tag block for each new master page for both the
OSGMasterPages Module and the
PublishingLayoutPreviewImages Module. Save the file. - Recycle the Application Pool for the site you plan to install the
Feature on, or reset IIS (Command Prompt - IISRESET). - You are now ready to reinstall the updated Feature on the web server. Open a
Command Prompt and enter the following:- Change directories to the BIN folder in the
12 hive so you can use STSADM.exe:
cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN - Launch STSADM and install the feature:
stsadm -o installfeature -name YourFeatureDirectoryName -force
Tip! To access STSADM quicker, refer to
Andrew Connell's SharePoint Developer Tip.
- Change directories to the BIN folder in the
- Now we will deactivate and reactivate the feature on the site.
- Open your site and navigate to the Site Collection Features settings
page. Site Actions - Site Settings -
Modify All Site Settings -
Site Collection Features (under the Site Collection
Administration submenu). - Your existing feature will be listed:
- Select Deactivate.
- A warning message will appear. Select Deactivate the
feature. - The Feature list will reload. Select Activate
next to your custom feature.
- Open your site and navigate to the Site Collection Features settings
- Your new master pages are ready for use.
In my next article I will cover what to do next with your custom master
page and how do you start customizing it.
No comments:
Post a Comment