views:

550

answers:

1

I have created a simple site definition for WSS 3.0 which uses a feature, this feature provisions a master page into the masterpage gallery.

This works absolutely fine, and once I've created a site from the definition I can go into the masterpage gallery and view my provisioned file.

If, however, I set the MasterUrl in my Configuration node of onet.xml and then create a new site from it, it fails. After clicking create it redirects me to the new site automatically but presents me with a file not found error. So I type in the url to the settings page and click to view the masterpage gallery which then gives me a file not found error again.

I'm not sure what's going on, but it looks to me like setting the MasterUrl prevents it from creating the correct lists to which the feature can provision the masterpage to. Can anyone shed any light on this matter for me please?

Here is the webtemp*.xml:

<?xml version="1.0" encoding="utf-8"?>
<Templates>
  <Template Name="MasterPageTest" ID="10902">
  <Configuration ID="0"
                 Title="MasterPageTest"
                 Description="Testing master page deployment"
                 Hidden="FALSE"
                 ImageUrl="/_layouts/images/stsprev.png"
                 DisplayCategory="Test"
                 />
  </Template>
</Templates>

And the onet.xml (with the masterurl attribute removed):

<?xml version="1.0"?>
<Project Title="MasterPageTest" Revision="3" ListDir="$Resources:core,lists_Folder;" xmlns:ows="Microsoft SharePoint" xmlns="http://schemas.microsoft.com/sharepoint/"&gt;
  <!-- _locID@Title="camlidonet1" _locComment="{StringCategory=HTX}" -->
  <NavBars>
  </NavBars>
  <ListTemplates>
  </ListTemplates>
  <DocumentTemplates>
  </DocumentTemplates>
  <Configurations>
    <Configuration ID="0"
                   Description="Testing master page deployment"
                   Title="Master Page Test"
                   Name="MasterPageTest"
                   >
      <!-- MasterUrl="_catalogs/masterpage/MasterPage.master" -->
      <Lists>
      </Lists>
      <Modules>
      </Modules>
      <SiteFeatures>
      </SiteFeatures>
      <WebFeatures>
        <!-- Masterpage -->
        <Feature ID="8175B375-38F5-44E2-950A-9600D5427E17"/>
      </WebFeatures>
    </Configuration>
  </Configurations>
  <Modules>
  </Modules>
  <ServerEmailFooter>$Resources:ServerEmailFooter;</ServerEmailFooter>
</Project>
+2  A: 

My first thought was: Why in the onet.xml?

I usually do this using a process called Feature stapling. It is impossible to remove / disable functionality created from a site definition later on (off course you could by hand, or a feature + receiver to remove say a list you don't need for a particular site created from the onet.xml, but you probably get the point).

By using feature stapling, (your / the) site definition stays clean and stays what it is meant to be: a definition of a site, that can be selected during site creation. IMHO, it should be nothing more than an empty container.

Feature Stapling binds features you want activated when a site is created to a (custom) siteTEMPLATE. You can even use this to attach features you want activated on out of the box site definitions as well. For instance, feature stapling is the preferred way of enabling features in the "MySite" and "My Site Host" definitions. The original sitedefintion remains untouched, but your features are activated too!

Now to actually answer your question: The masterpage is probably not available yet when the site definition is used, the onet.xml is processed before any features are activated.

If your site is a publishing site (meaning the publishing related features are activated in the site collection), you can set the masterpage in the Publishing Feature with the ChromeMasterUrl property.

If the site is a regular site, you can do 2 things:

  • deploy the master page from the onet.xml by moving the <Module> from your masterpage feature to the onet.xml, more info here (figure 1).
  • don't set the masterpage url in the onet, but use a feature + featurereceiver to set the masterpage url, more info here (downloadable code in article).
Colin
Hi Colin,Thanks for your response. It does make sense to keep everything out of onet.xml, I intend to take the feature stapling approach from now on.Regarding the master page, however, I used similar code to that in the link you provided, but whenever I set the master page to anything other than the default.master, it produces the same results as the onet.xml approach did previously. That is, I appear to get no master page gallery (404 on accessing it).Any ideas?Matt
Matt
After some playing around it seems it was a problem with the minimal master page I was using for testing. After copying the default master from the global directory I was able to get this all working. Thanks for your help Colin.
Matt