Tuesday, March 18, 2014

Group SharePoint site templates within a site definition using configuration elements

An organization may require multiple site templates designed for each department or team. Each template may contain it’s own navigation, libraries and features associated with them. To build such templates we normally tend to create multiple site definitions.

But that’s not the best approach to fulfill the requirement. Instead of multiple site definitions, we can create multiple configuration items within the same site definition.

Following scenario shows the onet.xml file of a site definition which contains two configurations created for HR department and Finance department.


Given below is the configuration section for ContosoHR which contains custom lists and some features

  1. <Configuration ID="0" Name="ContosoHR">
  2.       <Lists>
  3.         <List
  4.         FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101"
  5.         Type="101"
  6.         Title="HR Documents"
  7.         Url="$Resources:core,shareddocuments_Folder;"
  8.         QuickLaunchUrl="$Resources:core,shareddocuments_Folder;/Forms/AllItems.aspx" />
  9.       </Lists>
  10.       <SiteFeatures>
  11.         <!-- BasicWebParts Feature -->
  12.         <Feature ID="00BFEA71-1C5E-4A24-B310-BA51C3EB7A57" />
  13.         <!-- Three-state Workflow Feature -->
  14.         <Feature ID="FDE5D850-671E-4143-950A-87B473922DC7" />
  15.       </SiteFeatures>
  16.       <WebFeatures>
  17.         <!-- TeamCollab Feature -->
  18.         <Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5" />
  19.         <!-- MobilityRedirect -->
  20.         <Feature ID="F41CC668-37E5-4743-B4A8-74D1DB3FD8A4" />
  21.         <!-- WikiPageHomePage Feature -->
  22.         <Feature ID="00BFEA71-D8FE-4FEC-8DAD-01C19A6E4053" />
  23.       </WebFeatures>
  24.       <Modules>
  25.         <Module Name="DefaultBlank" />
  26.       </Modules>
  27.     </Configuration>

Then we need to modify the web template file (webTemp_ContosoSites.xml file in this example) to include our custom configurations.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Templates xmlns:ows="Microsoft SharePoint">
  3.   <Template Name="ContosoSites" ID="10002">
  4.     <Configuration ID="0"
  5.                    Title="Contoso HR Site"
  6.                    Hidden="FALSE"
  7.                    ImageUrl="/_layouts/images/CPVW.gif"
  8.                    Description="Contoso HR Site"
  9.                    DisplayCategory="Contoso Sites">
  10.     </Configuration>
  11.     <Configuration ID="1"
  12.                    Title="Contoso Finance Site"
  13.                    Hidden="FALSE"
  14.                    ImageUrl="/_layouts/images/CPVW.gif"
  15.                    Description="Contoso HR Site"
  16.                    DisplayCategory="Contoso Sites">
  17.     </Configuration>
  18.   </Template>
  19. </Templates>

After deploying the site definition, we can see multiple templates available under “Contoso Sites” section


By doing this we can properly group our site templates. Furthermore this is the way how SharePoint groups it’s default site templates (e.g.: Team Site, Blank Site, etc..)

1 comment:

Unknown said...

Thanks for the information. I have just signed up for a free SharePoint site with http://www.cloudappsportal.com