Create a custom Web Template in Sharepoint 2010

Before we start creating a custom Web template, I think it’s important to understand do we really need to create one? Even though web templates are easy to create and maintain as compared to site definitions, I would not recommend web templates simply because of the fact that they gets stored in content database. Thus, there is always an extra round trip to the database server which is not a good idea for high performance sites.

My personal choice is not to use custom webtemplate or custom site definition, just go with Microsoft recommendation i.e. to construct Microsoft SharePoint Foundation solutions as one or more features and apply all the customizations to your site through features. These features can be given the job to customize the look and feel of site by applying custom master page, custom style sheets  etc. Staple these features, by using Feature Stapling, with any out of the box site definition (such as Team site, Blank site etc) whichever fits closer to your business needs. Please see my other blog about ‘Feature Stapling’.

However, if a custom site type makes the most sense for your solution, then you can follow the steps below to create one.

1) Create a SharePoint site using any OOB site definition. Customize the look and feel of site using browser or sharepoint designer and save the site as Site template by going to ‘Site Actions ->Save site as template’. This will save your site template as wsp file in Solutions gallery. Import wsp file somewhere in the file system.

2) Open Visual studio and create a new project of type ‘Import Solution Solution Package’. This project will allow to import wsp file into visual studio project. During project creation, you will be prompted to choose wsp file. Just browse to the path where wsp file is downloaded and click ‘OK’.

3) In the visual studio project, look for onet.xml under ‘WebTemplates’ folder in the folder hierarchy. Copy it somewhere and close this project.

4) Now, Open your main sharepoint solution in Visual studio. Add new item of type ‘Empty Element’. In its Elements.xml file, add the code below –

<WebTemplate Name=[SomeTemplatename]Title=[SomeTitle]” SiteBaseTemplateID=1BaseTemplateName=STSBaseConfigurationID=0 DisplayCategory=“[Displaycategory]/>

 Please note that values of BaseTemplateId, BaseTemplateName and Base ConfigurationID should be the same as defined in the onet.xml of OOB site definition which was used to create the site which was saved as site template. In this example, my base site definition was Team site(STS#0), thus BaseTemplateName is ‘STS’ and BaseConfigurationID is ‘0’.

5) Copy the Onet.xml ( copied in step 3 above) in the same folder/level of ‘Elements.xml’. From this Onet.xml, you can remove  all the enteries under “<SiteFeatures>” and “<WebFeatures>” xml elements. Activation of these OOB features will be taken care by the base site definition. Instead you can add you own custom features under this section.

6) Finally, In SharePoint solution add a new farm scoped feature and associate it with the ‘Empty element’ just created above. Please note that Web Templates can only be deployed using farm scoped features.

Install and deploy your solution. Open sharepoint Central Administration. Go to Application Management -> Create Site Collections. Under ‘Template Selection’ section, you should see your custom web template among other OOB site definitions/templates.



Leave a Comment

Your email address will not be published. Required fields are marked *