Search This Blog

Thursday, July 1, 2010

Custom Master Page


Create a Feature: Add Custom Master Pages to your Site Collections



  1. Navigate to the Features directory on your web server:


    Local Drive:\Program Files\Common
    Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES

  2. 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.


    Location of custom feature folder

  3. 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).

  4. 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.


    Feature folder contents



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






  5. 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

  6. 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>

  7. Update the properties to reflect the new master page details:

    1. Change the URL to your custom master page.:

      <File Url="Sample.master" Type="GhostableInLibrary">


    2. 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


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

    4. Update the image names:

      <File Url="Sample.png" Name="Preview Images/Sample.png"
      Type="GhostableInLibrary">




  8. Save the ProvisionedFiles.xml file.

  9. Create a preview image in the language folder (in this case,
    en-us
    ).


    Preview image location

  10. 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

  11. There are four things you need to edit in this file:

    1. 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"

    2. Update the title:

      Title="Custom Master Pages"

    3. Update the description:

      Description="Custom master
      pages for use across multiple site collections.
      "


    4. Change the Hidden state to False:

      Hidden="False"



  12. Save the Feature.xml file.


  13. Recycle the Application Pool for the site you plan to install the
    Feature on, or reset IIS (Command Prompt - IISRESET).

  14. You are now ready to install the new Feature on the web server. Open a
    Command Prompt and enter the following:

    1. 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

    2. Launch STSADM and install the feature:


      stsadm -o installfeature -name YourFeatureDirectoryName


    Tip! To access STSADM quicker, refer to

    Andrew Connell's SharePoint Developer Tip
    .


  15. Now we will activate the feature on the site.

    1. 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).


    2. The new feature will be listed:

      Custom feature in Feature list

    3. Select Activate.



  16. 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).


  17. 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. 


    Master page selection drop down



    1. Select OK.



  18. 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.


    Sample Master Page



 


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.




  1. Navigate to your custom master page Feature directory and add the
    appropriate files for your new master pages.

  2. 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.

  3. Recycle the Application Pool for the site you plan to install the
    Feature on, or reset IIS (Command Prompt - IISRESET).

  4. You are now ready to reinstall the updated Feature on the web server. Open a
    Command Prompt and enter the following:

    1. 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

    2. 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
    .

  5. Now we will deactivate and reactivate the feature on the site.

    1. 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).


    2. Your existing feature will be listed:

      View of Active Feature

    3. Select Deactivate.

    4. A warning message will appear.  Select Deactivate the
      feature
      .


    5. The Feature list will reload.  Select Activate
      next to your custom feature.



  6. 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