Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Associating a Masterpage with a site definition

  Asked By: Grant    Date: Sep 11    Category: Sharepoint    Views: 3671

Is there any way to link a masterpage to a site definition?
The scenario is that a person creates a site using a custom site
template created from a custom site definition. The hope is that once
the site is created, the person will not have to go into the site
settings and choose the appropriate masterpage. Once the site has been
created, it will already be using the desired masterpage.
Does anyone know how to make this happen?
Is it even possible?



15 Answers Found

Answer #1    Answered By: Vinay Thakur     Answered On: Sep 11

If you are using an actual custom site  definition and not a site template the
answer is YES. There are three steps involved.

1) There are two attributes of the Configuration element in the Site
Definition (MasterUrl and CustomMasterUrl) that can be used to set the URL of
the default.master and Custom.master. You would point these at something like

2) Then create a Module in the Modules section of the Site definition  to
ghost the MyCustom.Master to the master page gallery where your MasterUrl
setting will load it from. (I've got a BLOG entry here that talks about how to
create a Feature to do this, but the Module declaration is the same).

3) Reference the new Module in the Configuration Modules section to ghost
the master page when the site is created.

FYI - the CustomMasterUrl is the setting for the ~masterUrl/Custom.master token
and isn't normally used outside of a publishing site. But you can use it on
your own pages if you like.

Answer #2    Answered By: Shameka Rich     Answered On: Sep 11

When you say "If you are using an actual custom site  definition and not a site
The plan is to copy an existing site definition  (probably sts) and modify it..
Would your response work with this scenario?

Answer #3    Answered By: Royce Orr     Answered On: Sep 11

Yes, I meant doing that as opposed to the "Save site  as Template" route. A lot
of people don't really differentiate between the two since they show up in the
same place when creating sites. But their capabilities are very different. If
you copy the ONET.xml in STS to make your site definition  then you are creating
a site definition not a site template.

Answer #4    Answered By: Laura Walker     Answered On: Sep 11

I looked at your instructions, also found two blog entries supporting this..
They are as follows

I followed the steps and when I created  a site  from the custom  site definition,
I got a 403 error..Website declined to show this web page
Any ideas why this might have happened?

Answer #5    Answered By: Nina Banks     Answered On: Sep 11

If you navigate directly to the site  Settings page
http://site/_Layouts/settings.aspx and check the master page gallery is the
master page there? (you can navigate there direct because it uses
Application.master and will be unaffected by your site's masterpage  setting.)

If the master page isn't there then either there is something wrong in the
<Module> or you didn't call the <Module> by adding it to the <Modules> section
of the configuration. If its refusing to show the page then its probably
resetting the master page, but can't find the page.

Answer #6    Answered By: Renee Murray     Answered On: Sep 11

I was able to get to the site  settings, but wasn't able to even view the
masterpage gallery. Same result..403 error...

Answer #7    Answered By: Harshini Raju     Answered On: Sep 11

The Master page gallery doesn't use application master so you'll need to use the
master page link  on site  settings to change the master page so that you can look
to see if its in the gallery. You are sure the master page itself works?

Answer #8    Answered By: Christop Mcfadden     Answered On: Sep 11

I am sure that it works..I have manually applied it to sites and it does work.

Answer #9    Answered By: Gopal Jamakhandi     Answered On: Sep 11

does it matter if I have a copy of the master page in the folder of the site

Answer #10    Answered By: Chantal Rosa     Answered On: Sep 11

That's where the <Module> would be copying the master page from, so it should be
in that directory.

Answer #11    Answered By: Kyla Eckert     Answered On: Sep 11

it is there..and was there when I tried this the first several times.

Answer #12    Answered By: Alisha Holmes     Answered On: Sep 11

Two other possibilities.

1) What does your MasterUrl property read in the ONET.xml. It's very easy
to get a mistake there.

2) Are you creating the site  in a site collection with Publishing
Infrastructure turned on? If so, then the master page you reference has to be
one in the master page gallery of the root site.

Answer #13    Answered By: Alexis Ellis     Answered On: Sep 11

Can I assume this is done in onet.xml?
If not, where is this done?

Answer #14    Answered By: Percy Beach     Answered On: Sep 11

See Point 1) in my response and substitute Onet.xml for site  definition. In
other words, there are two attributes of the configuration element in the
ONET.xml of a site definition, MasterUrl and CustomMasterUrl. These set the URL
settings used by pages in the site that reference ~masterurl/default.master and
~masterurl/custom.master respectively as their masterpage  location.

Answer #15    Answered By: Mary Adams     Answered On: Sep 11

Is it as simple as just adding the entries to onet.xml?
Do you have a sample of code I can look at and try to emulate?
I saw your blog on using a feature to do this..but I won't be using a feature at
this point..

Didn't find what you were looking for? Find more on Associating a Masterpage with a site definition Or get search suggestion and latest updates.