There are two confusing terms in MOSS 2007, site templates and site definitions.
A site template is a .stp file which contains only the difference of changes from the
Original site definition. A user wants to install a custom .stp file must have a site
Definition installed from which the .stp file was saved.
(Note: In MOSS B2, you can only save top level sites. i.e. site collection as a site
Template. This is a bug and will be corrected in B2TR.)
A site definition on the other hand is a complete definition with a directory structure
Containing .aspx files and important Onet.xml file.
We will create here a simple site definition which when applied shows a custom webpart
The site definitions are stored in this directory
\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates
Each site definition needs an entry in webtemp*.xml file which are located here
\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML
To begin with:
Make a copy of this directory
Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\sts
In the Site Templates directory and name it sample. This will create a site definition named sample having the
Same structure as team site i.e. sts directory.
Now to make it appear in the create site list, create a file named webtempsample.xml in the directory
And paste these contents
<?xml version="1.0" encoding="utf-8" ?>
<!-- _lcid="1033" _version="12.0.4017" _dal="1" -->
<!-- _LocalBinding -->
<Templates xmlns:ows="Microsoft SharePoint">
<Template Name="SAMPLE" ID="10001">
ID="0" Title="Sample Site" Hidden="FALSE"
ImageUrl="/_layouts/images/stsprev.png" Description="This sample
template creates a site for teams to create, organize, and share
information quickly and easily. It includes a Document Library, and
basic lists such as Announcements, Calendar, Contacts, and Quick
Links." DisplayCategory="Custom Site Definitions" > </Configuration>
ID="1" Title="Sample Blank Site" Hidden="FALSE"
ImageUrl="/_layouts/images/stsprev.png" Description="This sample
template creates a Windows SharePoint Services-enabled Web site with a
blank home page. You can use a Windows SharePoint Services-compatible
Web page editor to add interactive lists or any other Windows
SharePoint Services features." DisplayCategory="Custom Site
ID="2" Title="Sample Document Workspace" Hidden="FALSE"
ImageUrl="/_layouts/images/dwsprev.png" Description="This sample
template creates a site for colleagues to work together on documents.
It provides a document library for storing the primary document and
supporting files, a Task list for assigning to-do items, and a Links
list for resources related to the document." DisplayCategory="Custom
Site Definitions"> </Configuration>
Reset the IIS and try creating the new site. We will get a custom tab while choosing the site definition which
Now the important bit, we will now modify the site definition file onet.xml and place a custom webpart in the definition
So that when site definition is created, a custom webpart appears on the page.
I assume we have a custom webpart .dll and .dwp file ready.
Open the onet.xml file from
\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\sample\xml
This is the main file of the site definition and it stores the structure of whole site definition.
Observe this section of the file, the <modules> tag.
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" xmlns:iwp="http://schemas.microsoft.com/WebPart/v2/Image">
<Assembly>Microsoft.SharePoint, Version=22.214.171.124, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
If we try to understand this section, we also have an .aspx file in our site definition directory. If we observe the .aspx
File, we will see that it defines two webpart zones, left and right . See the snippet below of .aspx file :
The ids of webpart zones are left and right respectively.
<table width="100%" cellpadding=0 cellspacing=0 style="padding: 5px 10px 10px 10px;">
<td valign="top" width="70%">
FrameType="TitleBarOnly" ID="Left" Title="loc:Left" />
<td valign="top" width="30%">
FrameType="TitleBarOnly" ID="Right" Title="loc:Right" />
The onet.xml defines which webpart goes into these zones and the order of those webparts. If we see the line number
Five above, it defines the right webpart zone and places the .dwp file of the out of the box ImageWebPart in the
Now delete everything in the CDATA section and place the .dwp file of your custom webpart. We will also have to place
The .dll file in the web application bin directory.
Now again reset the IIS and create a new site based on this definition.
When we will create a site out of this customized site definition, we will get a custom webpart already created on the site
On the right zone.
There are lots of possibilities in customization of onet.xml file. We could have modified the left webpart and zone and
Place another webpart there. Or we could have modified an .aspx file and added more webpart zones.
If that's not enough, we could have added our own custom .aspx file and added its entry in the modules section of the
Onet.xml file. The possibilities are endless !
Mail me your comments and suggestions. I can mail the custom site definition discussed here to the interested.
PingBack from http://stevepietrek.com/2008/04/01/links-412008/
Can u Provide me a Sample example for adin a custom web part in Onet.xml
I need a sample to add a custom webpart too... because y have this piece of code
<AllUsersWebPart WebPartZoneID="Left" WebPartOrder="3">
<Assembly>CustomWebParts,Version=126.96.36.199, Culture=neutral, PublicKeyToken=32157ab92e2e1d47</Assembly>
<property name="Title" type="string">ISGPageViewer</property>
and this throw the error:
Web Part Error: One of the properties of the Web Part has an incorrect format. Windows SharePoint Services cannot deserialize the Web Part. Check the format of the properties and try again.
How did you get the webpart definition, the content between CDATA. Try to copy it from the .dwp file.
Can you tell me how to include a custom listwebpart in CDATA
nice post..explained in detail...
Can you talk more about adding different web parts and css to the site defnition, do we need to specify the web part which we want to be added or just the web part zone for adding web part when using this site defnition.
I have the same error as Nico... though I am using the data from the .webpart file.
Thanks for this interesting post,