Thursday, September 20, 2012

The web template feature in SharePoint 2010

In SharePoint 2007 you had two options when you needed to create a new template for a SharePoint site:

In SharePoint 2010, there is a new replacement and improved framework for handling site templates. When you save a site as template it will create a normal SharePoint Solution Package (a wsp file – if this is new for you take a look at WSP – SharePoint Solution Files). The new webtemplate feature allows you to build a “site definition” which is scoped to a site collection – this way you can built templates of a site and still deploy them to the SharePoint solution gallery in sandbox mode.

Every webtemplate is based on an existing site definition – listed below is a code sample using the minimal set of attributes that you have to use when creating a new webtemplate.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
Title="JOPX WebTemplate"

The WebTemplate has to reference the Template (BaseTemplateName) and the configuration of the site definition (BaseConfigurationId) the template is based on.

The example on MSDN How to: Create a webtemplate starts from importing an existing saved webtemplate but in some cases it is easier to start from an empty SharePoint project and manually adding a elements.xml incorporating the webtemplate feature as well as the ONET.XML from the site definition from which you want to start.


No comments: