Showing posts with label Site Definitions. Show all posts
Showing posts with label Site Definitions. Show all posts

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.

image

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

image

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..)

Monday, March 10, 2014

Deploy site definitions to both SharePoint 2010 and SharePoint 2013 experience versions

When we deploy a site definition in SharePoint 2013, it will be deployed to 15 hive. Hence it will be listed in the template selection section. But as expected it will not be listed if we select the experience version as 2010

image

But what if we need the template to be available in both 2010 and 2013 experience versions. It’s very simple, we just need to specify the CompatibilityLevel switch when deploying the solution. To learn more on compatibility levels you can refer this article

  1. Add-SPSolution -LiteralPath "C:\Deploy\STSTest.wsp"
  2. Install-SPSolution -Identity STSTest.wsp -CompatibilityLevel14,15” -GACDeployment -force

Then the template will be available for 2010 experience version as well

image