Monday, February 20, 2012

Customizing SharePoint Sites and Portals: Using Templates and Site Definitions

Applies to:
    Microsoft® Windows® SharePoint™ Services
    Microsoft Office SharePoint Portal Server 2003
    Microsoft Office FrontPage® 2003

Introduction

Microsoft® SharePoint™ Products and Technologies consists of Microsoft Office SharePoint Portal Server 2003 and Microsoft Windows® SharePoint Services. SharePoint Products and Technologies use Microsoft Windows Server™ 2003 and the .NET Framework. This latest version offers improvements in the customization, development, and deployment of an enterprise portal and team collaboration infrastructure.
Customization is the ability to change the layout, view, content, and site structure for a group of users such as a department or corporation. To help ensure consistency, Windows SharePoint Services and SharePoint Portal Server 2003 enable only Web Designers and Site Administrators full customization privileges for managing the look and feel of a site.

Templates and Site Definitions

There are two ways you can customize SharePoint sites. You can use custom templates or create site definitions. Custom templates enable you to customize a site by using the user interface (UI). For example, you can derive a custom list from an existing list, or create a custom list to use as a list template that Site Administrators can choose from a list of available list templates. Windows SharePoint Services stores all custom templates in the content database. You can customize list and site templates from Top-level Site Administration or by using Microsoft Office FrontPage 2003.

Site definitions are composed of multiple files located in the file system of each Web server. Site definitions and templates work together to customize a site. Custom templates are always associated with the site definition on which the template is based. A custom template depends on the base site definition in the file system in order to work. A custom template is the difference between a site definition and the state of the site after a template is generated. The template tracks changes to the site definitions that are stored in the configuration database. This article describes the advantages and disadvantages of using custom templates and site definitions and provides guidance about when to choose one over the other, and how to avoid overwriting custom templates and site definitions when installing product updates.

Creating Custom Templates

Now that we know that custom templates track changes to a SharePoint site definition, we can examine the different types of custom templates. List templates track changes to columns, forms, pages, and optionally, changes to the content associated with a specified list. Site templates track changes to site navigation, Web Parts, lists present on a site, and optionally, changes to the content of a single site. You can save an existing site as a site template.
Note   There is a 10 MB quota on the total size of the content you can store in a site template. You can determine the size of site content by going to Top-Level Site Administration, and in the Management and Statistics section, clicking View site usage data.
A custom template is persisted as a file with an .stp extension, which is actually a .cab file that you can rename with the .cab file extension and open in Windows Explorer. This file includes one Manifest.xml file in Collaborative Application Markup Language (CAML) that the server generates as a subset of the Microsoft SharePoint Migration Tool (Smigrate.exe) manifest file format. For more information about SMIGRATE, see "Introduction to Templates and Definitions" in the Microsoft SharePoint Products and Technologies 2003 Software Development Kit (SDK).

Let's say that you created a site, customized it by adding lists, events, document libraries, custom Web Parts, and applied a special theme. You want to share this piece of work with other site owners or impose this site template on any subsites. On the Site Settings menu, click Go to Site Administration, and then in the Management and Statistics section, click Save as template. Type a file name using an .stp extension and type a title and description for your site template. You can also select the Include content check box. You save your site as a template in a gallery inside the content database to make it available to other subsites. As long as subsequent subsites are based on the same site definition (for example, on a Document Workspace) and have the identical language of the original site, you can create subsites using this template.

To make the template appear in the list of templates in the Site Creation wizard, you need to export the template to the file system and run the STSADM command tool. To export the template, right-click the template and click Save Target As, and then follow the prompts to save the template. After saving the template to the file system, from a command prompt, type the following:


stsadm.exe -o addtemplate -filename 
"local_drive:\site_template_file_name.stp" -title "Site_Template_Name"
 
Note   You must reset Microsoft Internet Information Services (IIS) before these changes can take affect. After resetting IIS, the Site_Template_Name template becomes available in the site template list during site creation.
You can also export a list template the same way you exported the site template. However, list templates are available only to the site collection of the site from which you exported.

About Collaborative Application Markup Language

Collaborative Application Markup Language (CAML) is an XML-based language used for defining collaboration objects for a site. In Windows SharePoint Services, CAML defines sites, lists, fields, views, or forms.
CAML essentially has two major types of elements—those for field rendering and schema definition, and those for page rendering. For example, you can use the page-rendering CAML elements when you need to extract the property of a specific field and render it on a page.
You can also use CAML to define tables in the site database during site provisioning. You can use CAML to customize a SharePoint site and in SOAP messaging to Web services in Windows SharePoint Services to interact remotely with a Windows SharePoint Services deployment. Moreover, you can use CAML in script or code that implements members in the Windows SharePoint Services object model. In this case, you pass CAML strings through method parameters, assign them to properties, or return them by methods and properties.
For more information about CAML, see "Introduction to Collaborative Application Markup Language (CAML)" in the Microsoft SharePoint Products and Technologies 2003 Software Development Kit (SDK).

Creating Site Definitions

Site definitions are similar to templates. Site definitions are composed of several files located in the file system on each Web server. The site definition files contain XML tags that define a template for a site. The default site types included with Windows SharePoint Services are created using site definitions (such as Team Site, Blank Site, Document Workspace, and so on). Windows SharePoint Services creates a version of each site definition during installation. The site definition files are stored in subdirectories in the following location:

Local_drive:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\


It is recommended that you create a custom site definition by copying an existing site definition, rather than modifying the original files installed with Windows SharePoint Services. Changes that you make to originally installed files may be lost when you install updates or service packs for Windows SharePoint Services, or when you upgrade a deployment to the next product version.

To create a site definition

1. Copy the existing site template folder in the following location:
Local_drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\Template\lcid


For example copy the site template folder and rename it "TRAINING".

2. Then copy the WEBTEMP.XML file in the following location:
Local_drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\1033\XML

 3. Rename the file, for example, WEBTEMPTRAINING.XML.

During initialization, the compiler merges the information contained in files prefixed with WEBTEMP*.XML and makes them available for creating sites. This provides easy extensibility for third-party ISVs to create additional site definitions that integrate with SharePoint Products and Technologies.
Note   All areas in a SharePoint Portal Server deployment are stored in directories that begin with /SPS*.
A site definition is composed of three main files: WEBTEMP.XML, ONET.XML, and SCHEMA.XML. The following table shows the files' locations in the file system, and their definitions.

Table 1. Site definition files

Site Definition FileLocationDescription
WEBTEMP.XMLLocal_drive:\Program Files\Common Files\Microsoft Shared\Web server extensions\60\TEMPLATE\1033\XMLSpecifies configurations of lists and modules for a site definition.
ONET.XMLLocal_drive:\Program Files\Common Files\Microsoft Shared\Web server extensions\60\TEMPLATE\1033\*\XMLDefines navigation bars such as the top link bar and the quick launch, available lists, document templates, base types, configurations, modules
SCHEMA.XML
Local_drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\1033\Custom_Site_Template\LISTSDefines the columns, views, and contents of a list

WEBTEMP.XML

A WEBTEMP.XML file contains the site definitions that are available on the Template Selection page for creating instances of sites. WEBTEMP.XML defines the site template for a site definition. By default, Windows SharePoint Services includes the following site templates: Team Site, Blank Site, Document Workspace, and Meeting Workspace.

You can edit the default WEBTEMP.XML file to modify the existing list of templates available to users. To hide a particular template on the list of site templates, locate the section for that template in the WEBTEMP.XML file, and then set the Hidden attribute of the Configuration element to TRUE. Set Hidden to FALSE to make the template visible.

Remember to copy and rename the WEBTEMP.XML file before making changes to the default version. In the following example, we use the copied and renamed file WEBTEMPTRAINING.XML to create a Training Team Site and a Trainee Workspace.
 
 
 WEBTEMPTRAINING.XML
<?xml version="1.0" encoding="utf-8" ?>
<Templates xmlns:ows="Microsoft SharePoint">
   <Template Name="TRAINING" ID="10101">
      <Configuration ID="0" Title="Training Team Site" Type="0"
         Hidden="FALSE" 
         ImageUrl="images/stsprev.jpg" 
         Description="This template provides a forum 
         for the team to create, organize, and share information
         quickly and easily. It includes a document library, and
         basic lists such as Announcements, Events, Contacts, 
         and Quick Links.">   
      </Configuration>
      <Configuration ID="1" Title="Trainee Workspace" Type="0"
         Hidden="FALSE"
         ImageUrl="images/dwsprev.jpg" 
         Description="This definition creates a site for Trainees
         to work together on specific documents.">   
      </Configuration>
   </Template>
</Templates>
 
 
The WEBTEMPTRAINING.XML file contains a Template element used to define a single template for a site. Each Template element has a Name attribute that must match the name of the XML file prefixed with webtemp. For example, the value of the Name attribute (in this example, training) is the same as the file name following the prefix of webtemp. During initialization, Windows SharePoint Services scans for files with a prefix of webtemp*.xml and loads them into memory.
Note   For changes to appear, you must reset Internet Information Services (IIS) whenever making changes to any of the WEBTEMP*.XML files.
A site definition only needs one root Template element. To avoid conflict with IDs already used by Windows SharePoint Services, use unique values greater than 10,000 for the ID attribute.


The WEBTEMPTRAINING.XML file creates additional template options for selecting a new template during site creation, as shown in Figure 1.












 
 
 
 
 
 
 
Figure 1: Training Workspace and Training Team Site templates are created 

ONET.XML

The ONET.XML file defines the top link bar and the Quick Launch
 bar. It also specifies the default document and list templates that are
 available for a Web Part Page such as document library, picture 
library, custom list, discussion boards, surveys, and so on. The 
ONET.XML file also specifies the configuration of files to include 
during site creation, and includes modules that identify the location of
 these files during site creation.  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Figure 2. Default options specified in the ONET.XML file 
 
 
For detailed information, see "ONET.XML" in the Microsoft SharePoint Products and Technologies 2003 Software Development Kit (SDK).

Customizing the Navigation Bar for a Site

You can customize the navigation bar of an existing site by adding a NavBarLink element to a NavBar element within the ONET.XML file for a custom site template. You can add links to local files and pages on the server or to files and pages located elsewhere.

The following example adds two NavBarLink elements, one that provides a link to a local file on the server, called Sample.aspx, and the other that provides a link to a URL, http://example.microsoft.com/.
 
 
 <NavBars>
   <NavBar Name="SharePoint Top Navbar" ID="1002">
   <NavBarLink Name="Documents and Lists" 

Url="_layouts/[%=System.Threading.Thread.CurrentThread.CurrentCulture.LCID%]/viewlsts.aspx">
   </NavBarLink>
   <NavBarLink Name="Create" 

Url="_layouts/[%=System.Threading.Thread.CurrentThread.CurrentCulture.LCID%]/create.aspx">
   </NavBarLink>
   <NavBarLink Name="Site Settings"

Url="_layouts/[%=System.Threading.Thread.CurrentThread.CurrentCulture.LCID%]/settings.aspx">
   </NavBarLink>
   <NavBarLink Name="Get Current Data" Url="_layouts/Sample.aspx"></NavBarLink>
   <NavBarLink Name="microsoft" Url="http://example.microsoft.com/"></NavBarLink>
   <NavBarLink Name="Help" Url="javascript:HelpWindow()"></NavBarLink>
   </NavBar>
   <NavBar Name="Documents" ID="1004"> 
   </NavBar>
   <NavBar Name="Pictures" ID="1005"> 
   </NavBar>
   <NavBar Name="Lists" ID="1003"> 
   </NavBar>
   <NavBar Name="Discussions" ID="1006"> 
   </NavBar>
   <NavBar Name="Surveys" ID="1007"> 
   </NavBar>
</NavBars>
 
 

Using Site Configurations

When creating site definitions, the configuration identifies which lists and modules to include. A configuration allows a site definition to have multiple options for site layout and design such as Team Site, Blank Site, and Document Workspace. Each of these site templates result in a different configuration of lists and Web Parts. Both WEBTEMP.XML and ONET.XML include a Configuration element. In WEBTEMP.XML, this element is contained within the Template element and specifies the configuration options to include for the site definition.

In ONET.XML, the Configuration element is contained within a Configurations element that specifies one or more configurations containing lists and modules. Each Configuration element contains an ID attribute. The ID attribute associates the configuration specified in a site template with a configuration of list definitions in the ONET.XML file. The combination of this ID and the value of the Name attribute in the Template element provides a reference to the contents of a specific Configuration element in a ONET.XML file.
You can reuse existing list definitions specified in the ONET.XML file for a site definition. You can also create multiple configurations in a single ONET.XML file. In this approach, each configuration enables the creation of a site with a different set of lists, Web Parts, and layout.

Table 2. Configuration element attributes

NameDescription
DescriptionOptional Text. Contains the description of the site configuration that appears on the Template Selection page.
HiddenOptional Boolean. Specifies whether the site configuration appears as an option on the Template Selection page.
IDRequired Integer. Specifies a unique ID for the configuration.
ImageUrlURLOptional Text. Contains the URL for the preview image displayed on the Template Selection page.
NameOptional Text. Contains the name of the configuration.
TitleOptional Text. Contains the title of the configuration that is displayed on the Template Selection page.
TypeOptional Text. Identifies the configuration with a specific site definition.

o set up a configuration within a site definition, use Configuration elements within a custom WEBTEMP*.XML file and within one or more ONET.XML files that are referenced in the WEBTEMP*.XML file.
For example, the WEBTEMPTRAINING.XML file in the previous example uses two configurations to define different site configurations, one for a training team site and the other for a training Document Workspace site. This example involves use of only two configurations within a single site definition, but you can include multiple definitions with different configurations within a single WEBTEMPTRAINING.XML file, each one referencing different site definition directories and their respective ONET.XML files.

In the ONET.XML file, each configuration defines a specific type of site that can be created from the site definition. All configurations within this file share a set of available list definitions, document templates, navigation areas, base list types, and modules that are defined within the file. You can add a reference to a list that is defined in ONET.XML by adding a List element to the collection of lists specified within a Configuration element. For example, if you define a list type named "My_Custom_List" in ONET.XML with a Type attribute of 143, then you can add <List Title="My_Custom_List" Type="143" URL="Lists/My_Custom_List" /> to add the list to the configuration. The following example shows the arrangement of configurations in the ONET.XML file for a specific WEBTEMP*.XML file:

<Configurations>
   <Configuration ID="0" Name="Default">
      <Lists>
         <List Title="My_Custom_List" Type="143" Url="Lists/My_Custom_List" />
         <List Title="Shared Documents"  Url="Shared Documents"
  QuickLaunchUrl="Shared Documents/Forms/AllItems.aspx"
            Type="101" />
         <List Title="General Discussion" Url="Lists/General Discussion" 
QuickLaunchUrl="Lists/General Discussion/AllItems.aspx"
            Type="108" />
         <List Title="Announcements" Type="104" Url="Lists/Announcements" />
         <List Title="Links" Type="103" Url="Lists/Links" />
         <List Title="Contacts" Url="Lists/Contacts" QuickLaunchUrl="Lists/Contacts/AllItems.aspx" Type="105" />
         <List Title="Events" Type="106" Url="Lists/Events" />
         <List Title="Tasks" Url="Lists/Tasks" QuickLaunchUrl="Lists/Tasks/AllItems.aspx" Type="107" />
         <List Title="Site Template Catalog" Type="111" Url="_catalogs/wt" RootWebOnly="TRUE" />
         <List Title="Web Part Catalog" Type="113" Url="_catalogs/wp" RootWebOnly="TRUE" />
         <List Title="List Template Catalog" Type="114" Url="_catalogs/lt" RootWebOnly="TRUE" />
      </Lists>
      <Modules>
         <Module Name="Default"/>
         <Module Name="WebPartPopulation"/>
      </Modules>
   </Configuration>
   <Configuration ID="1" Name="DWS">
      <Lists>
         <List Title="Shared Documents" Type="101" />
         <List Title="Image Library" Type="109" />
         <List Title="General Discussion" Url="Lists/General Discussion"
            QuickLaunchUrl="Lists/General Discussion/AllItems.aspx" Type="108" />
            <List Title="Announcements" Type="104" Url="Lists/Announcements" />
          <List Title="Contacts" Url="Lists/Contacts" QuickLaunchUrl="Lists/Contacts/AllItems.aspx"
            Type="105" />
         <List Title="Links" Type="103" Url="Lists/Links" />
         <List Title="Events" Url="Lists/Events" QuickLaunchUrl="Lists/Events/AllItems.aspx"
            Type="106" />
         <List Title="Tasks" Type="107" />
         <List Title="Site Template Catalog" Type="111" Url="_catalogs/wt" RootWebOnly="TRUE" />
         <List Title="Web Part Catalog" Type="113" Url="_catalogs/wp" RootWebOnly="TRUE" />
         <List Title="List Template Catalog" Type="114" Url="_catalogs/lt" RootWebOnly="TRUE" />
      </Lists>
      <Modules>
         <Module Name="DWS"/>
         <Module Name="WebPartPopulation"/>
      </Modules>
   </Configuration>
</Configurations>
 
 

Using Modules

Modules serve two purposes. Modules specify all the files associated with a definition and they specify the location of these files in the new site. For example, if the file is a Web Part Page, the module definition specifies both the Web Part Page file itself and the specific set of Web Parts or lists, and files, to include on the page. The file is encapsulated inside the File element as a child element of the module.
You must declare modules as an element within the Configuration element. You can also use modules outside the configuration to define the URL of any file to include as part of the definition.
The following is an example from the ONET.XML that shows the use of modules:



<Module Name="Default" Url="" Path="">
   <File Url="default.aspx" NavBarHome="True">
     <View List="104" BaseViewID="0" WebPartZoneID="Left"/>
     <View List="106" BaseViewID="0" WebPartZoneID="Left" 
        WebPartOrder="2"/>
     <AllUsersWebPart WebPartZoneID="Right"WebPartOrder="1">
       <![CDATA[
         <WebPart xmlns=http://schemas.microsoft.com/WebPart/v2
         xmlns:iwp="http://schemas.microsoft.com/WebPart/v2/Image">
         <Assembly>Microsoft.SharePoint, Version=11.0.0.0,
         Culture=neutral,
         PublicKeyToken=71e9bce111e9429c</Assembly>
         <TypeName>Microsoft.SharePoint.WebPartPages.ImageWebPart
         </TypeName>
   <FrameType>None</FrameType>
   <Title>Site Image</Title>
      <iwp:ImageLink>/_layouts/images/homepage.gif
      </iwp:ImageLink>
   </WebPart>
      ]]>
      </AllUsersWebPart>
      <View List="103" BaseViewID="0" WebPartZoneID="Right"
            WebPartOrder="2"/>
      <NavBarPage Name="Home" ID="1002" Position="Start">
      </NavBarPage>
      <NavBarPage Name="Home" ID="0" Position="Start">
      </NavBarPage>
   </File>
</Module>

Note   HTML definitions do not allow for nested
<CDATA>
tags. However to work around this, you can remove the inner tag and use
HtmlEncode
on its content.
The URL attribute is required and designates the main file to execute for the module. For example, the URL could specify a Web Part Page such as default.aspx, or a *.dwp file for a specific Web Part. Inside the Module element, you can include Web Part definitions and placements inside a Web Part zone. The previous example specifies a single image Web Part displayed in the right Web Part zone.
You can also specify whether to display a module in the top navigation area of a page as well as placement in the Web Part zones of a page. In the previous example, views and Web Parts in the module are displayed on the Home page. After a Web site is created, it includes whatever files are specified through this module.

Field Definitions Using SCHEMA.XML

The SCHEMA.XML file defines the views, forms, and any special fields for a list. To customize a list with custom views, you can modify the SCHEMA.XML file and add a field to the list definition.

To add a field to a list definition

1. Go to the following directory:

Local_drive:\Program Files\Common Files\Microsoft Shared\Web Server
 Extensions\60\TEMPLATE\1033\Custom_Site_Template\LISTS



Each subfolder represents a specific list.
  1. Open the subfolder for the list you want to customize.
  2. Open the SCHEMA.XML file using a text editor such as Notepad.
  3. In the Metadata section of the file, find the Fields element that contains the definitions of each field in the list type. You can add a new field under the Fields element as follows:
<Field Name="EmployeeID" DisplayName="Employee ID" Type="Number"Required="TRUE"
   Description="Enter the ID from your employee badge."/> 
 
 
For more information, see "Creating a List Definition" in the Microsoft SharePoint Products and Technologies 2003 Software Development Kit (SDK).

Customizing the Toolbar for a List

To customize the toolbar for a list, you need to make changes to the Toolbar element within the SCHEMA.XML file for the list. To add a new link to the toolbar, for example, you can copy an existing definition for a link and then modify it. This maintains the nesting of tables that is used for displaying links and ensures that the appearance of the link you add is consistent with the other links.
The following example adds a link on the toolbar of a list to a document that is contained in the Shared Documents folder.

<tr><td style="padding-left: 2px;padding-bottom: 2px" width=100%>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr><td width=100% class="ms-unselectednav" colspan=2>
<table cellpadding=0 cellspacing=0 border=0><tr><td valign=top>
<img src="../../_layouts/images/rect.gif">&nbsp; </td>
<td><A  HREF="]]></HTML><HttpVDir/>
<HTML><![CDATA[/Shared Documents/MeetingNotes.doc">]]></HTML>
<HTML>Type Conversions</HTML><HTML><![CDATA[</A></td></tr></table>
</td></tr></table>
</td></tr> 
 

The example shows the toolbar link nested within three tables. The two tables in the example are contained within opening and closing <tr> and <td> tags that belong to a third table, which serves as the frame for containing all the links in the toolbar.
The CAML HttpVDir element, which returns the root directory of the current subsite, constructs the complete path for the URL.
When a new list is created based on this template, a link to a MeetingNotes.doc file appears in the toolbar.

Customizing Portal Areas Using Templates

You can select an area template to use when creating an area in SharePoint Portal Server. Area templates are site definitions that also consist of multiple files with a parallel structure to the site definitions in Windows SharePoint Services. They are stored in the following location:

 Local_drive:\Program Files\Common Files\Microsoft Shared\
      Web server extensions\60\template\1033

An area template can include:
  • A site home page
  • Lists for the site
  • Document libraries
The default naming convention for area template directories starts with the prefix SPS. The following table lists the template and the area it maps to.

Table 3. Area templates


 
 
 

No comments:

Post a Comment