Thursday, October 2, 2008

Creating and Deploying a Custom Master Page with STSDev (Refer to SharePointers)

(Continue from last one: Create Site Definition by STSDEV)

Step 1: Add the base master page to the project

If you haven't already done so, download and unzip the base master page from Heather Solomon's site.

  1. Right click on your 'RootFiles\TEMPLATE\SiteTemplates\YourSiteTemplateName' directory and choose 'Add Existing Item'
  2. Select the base master page from your file system and click 'Add'
  3. Rename the file 'SharePointersDemoCustom.master'.

Step 2: Editing the Default.aspx file

  1. Open the default.aspx file
  2. At the top of the page, change the 'Page' directives 'MasterPageFile' attribute to '~masterurl/custom.master' (note that this value can only be 'default.master' or 'custom.master' but you can name your file whatever you like because the onet.xml file's element contains the reference to the actual file)
  3. Save the file

Step 3: Editing the onet.xml file

  1. Open the onet.xml file
  2. In the <listtemplates> node add the following child node:


    <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" />

  3. Find the <configuration> node the 'ID' attribute of 0 (zero)
  4. Add the 'MasterUrl' attribute to the <configuration> node like so:

    <Configuration ID="0" Name="Blank" MasterUrl="_catalogs/masterpage/SharePointersDemoCustom.master">

  5. The <configuration> node you just modified should have a <modules> child element. Add the following <modules> tag as a child of this node

    <Module Name="CustomMasterPage" />


  6. Now go to the outer <Modules> tag that is a child of the main <Project> node and add the following child <Module> node

    <Module Name="CustomMasterPage" List="116" Url="_catalogs/masterpage" RootWebOnly="FALSE">
    <File Url="SharePointersDemoCustom.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />
    </Module>



Step 4: Deploy the project

  1. Again, STSDEV makes this a breeze. If this is the first time you've deployed this solution change your build configuration to DebugDeploy and do a build, otherwise do a DebugRedeploy.
  2. Now create a new site based on your site definition and see if your masterpage is working correctly. (Note, it should look pretty ugly since we haven't modified the UI yet.

Step 5: Start tweaking that master page!

Here's a bunch of really good resources for customizing your master pages all in one place. Heather Solomon really is the expert when it comes to SharePoint branding:

No comments: