When provisioning your SharePoint site automatically with a script – you often create site templates for your sites and sub sites to bundle up pieces of functionality such as page layouts and other features to be created and instantiated when a user creates new instance of your site template. One of the most common scenarios is the ability to provision Web Parts and their values on to a page that is a default page of your site template. This will make it look as if default web parts were added to the page when users create new instance of your custom site template.
To get started we will be using one of the out-of-the-box site templates and enhance it. Let’s grab STS template from ([Drive]:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates). Locate ONET.XML file in your template.
Locate <Configuration ID=”1″ Name=”Blank”> in the template. Navigate to the <WebFeatures> node. This is where the Web features will be activated when the template is instantiated.
The next step is to create a feature that will create a page upon being called. We will reference that feature right under the Web Features, by using ID just like all of the other features are referenced.
In ([Drive]:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\sts) you will find default.aspxwhich we will include in our feature. The default.aspx file already has some web part zones which you can change, delete and add new ones as you see fit.
So far our feature definition will look like this:
<?xml version="1.0" encoding="utf-8"?> <Feature xmlns="http://schemas.microsoft.com/sharepoint/" Id="090A251F-86DB-4035-959C-4A3E2FDEA856" Title="Provision my page" Version="1.0.0.0" Scope="Web" Hidden="FALSE" ActivateOnDefault="FALSE" AlwaysForceInstall="TRUE" ImageUrl=""> <ElementManifests> <ElementFile Location="Default.aspx" /> <ElementManifest Location="Default.aspx.xml" /> </ElementManifests> </Feature>
That’s Default.aspx.xml you’re looking at in the feature definition will define what web part are going to show up in which zones. Here is how we typically provision our web parts into zones:
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Module Name="Content"> <File Name="Default.aspx" Url="Default.aspx" Type="GhostableInLibrary"> <AllUsersWebPart WebPartZoneID="LeftZone1" WebPartOrder="1"> <![CDATA[Your webpart definition goes here]]> </File> </Module> </Elements>
That’s about it. Now all you need to do is to reference the feature ID in a WebFeatures section of your onet.xml.
I assume you already know how to provision your site template. Now when users create new instance of your template. You pre-formatted, so to say, page will be provisioned with it.
Good Luck!