We have a site collection that have several sub webs.

In the root site, we created some custom master pages.

We linked the subwebs masterpage url (SPWeb.MasterPageUrl) to the same, centralized masterpage, located at the root site (we are not duplicating the master page in all subweb).

If I export one of the web as a template, and if I create a new site based on this template, I don't have the correct master page applied. In fact, the system falls back to the default V4.master instead of keeping the link to the root.

Is it possible to preserve this property when creating the new subweb?

The master page is deployed on all root webs of all site collections. So I ensure the master page is always present.

1 Answer 1


2 Choices:

Get the template and edit the TEMPLATE/templatename/xml/onet.xml file to add the master page link manually (I would make a new VS project from this file and deploy it rather than edit it in the hive even though you can, this is purely because then you have a deployable copy of the template)

    <Configuration ID="0" Name="TemplateName" MasterUrl="_catalogs/masterpage/custom.master">

In this case I would create a feature stapler for the new template to set the master page.

Salman's blog on using a feature stapler to set the masterpage.

  • 1
    +1 Feature stapler is the way I've achieved this in the past. Works like a charm. Nov 15, 2012 at 21:37
  • Updating the template is not an option. The process is executed often, and by low-technical users. The users can manipulate the SharePoint UI, but no more. And FYI, I have a feature Stappler that set the master page. Unfortunately, as the source web site has the feature activated, the copy won't fire the feature activated event. Or I missed something?
    – Steve B
    Nov 16, 2012 at 8:36
  • The feature stapler fires on template use not on feature activated. But you can use feature activated on something like the basic web parts feature or something, if you wanted.
    – Hugh Wood
    Nov 16, 2012 at 8:39
  • Does an exported site have a specific site template ID? or will it inherits the original templateId?
    – Steve B
    Nov 16, 2012 at 8:56
  • 1
    That's a question I don't know the answer to, but checking the hive would give you that answer in a few seconds. If they get a new template ID, then I'm sure there is a way of hooking the feature stapler to that template programmatically too.
    – Hugh Wood
    Nov 16, 2012 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.