Skip to content

How to make a custom site template (stp) usable in several site collections but still use the same masterpage?

August 10, 2011

This was the question that we needed to find the answer and after rejecting several promising approaches, this was the way that we managed to solve this:

  1. Create a feature that deploys our masterpage to the site that will be used as a template. It’s elements.xml should look something like that:
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <Module Name="UploadMaster" Url="_catalogs/masterpage" >
            <File Url="my.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="True"/>
        </Module>
    </Elements>
    
  2. Activate this feature on the site.
  3. Set the masterpage of the site as this masterpage.
    web.MasterUrl = web.ServerRelativeUrl.TrimEnd('/') + "/_catalogs/masterpage/my.master";
    
  4. Save the site as template.

Then the sites created based on this template will use the my.master masterpage.

Note, that even if the masterpage of the site is set explicitly to the my.master, this masterpage is not customized in the site and it only points to the filesystem version of the file, that is in the 12\TEMPLATE\FEATURES\MyFeature folder

With redeploying the WSP solution that contains the feature, the masterpage can be updated easily for all already created sites.

One of the approaches we had to reject is activating the masterpage feature with a stapling feature. We had to learn however that feature stapling does not work for sites created from custom site templates (STP files)

Advertisements

From → SharePoint, WSS 3.0

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: