Using SharePoint Site Template functionality in Office 365

Posted by

Intro

The evolution of site templates has changed over time and we have a new approach to provisioning sites with a custom structure and look in SharePoint Online.  Site templates are a very valuable solution for customers in large part because of the ability to maintain a common structure and appearance for SharePoint sites across an organization.  Site templates as we knew them aren’t a recommended approach for applying a common look and feel to SharePoint sites in Office 365.  Instead, we introduced remote provisioning as the recommended approach for applying a common structure across site collections and sites.  The next question is what do I mean by common structure?

Common structure includes objects like the following:

  • Content types
  • Site Columns
  • Navigation Nodes (links)
  • Security (SharePoint Groups)
  • Managed Metadata Terms
  • Search Settings
  • Company Logo (picture)
  • Custom Master Page (FYI…not recommended to use custom master pages)
  • Custom CSS
  • Lists
  • Libraries
  • Fields
  • Webparts

 

The remote provisioning pattern describes the shift to provisioning sites outside of SharePoint by using CSOM and\or Add-Ins as well as provides some good examples.  I would like to point out one additional approach for remote provisioning by using the SharePoint Patterns & Practices (PnP) module.  SharePoint PnP is a PowerShell module which contains several SharePoint focused command-lets that provide advanced functionality that’s not part of the (OOB) out of the box SharePoint online command-lets.  In my case, I want every site to have the identical look and feel as a top-level site I refer to as a master site.  The master site was created using Classic Team Site template and setup with the following:

  1. Custom Content Type
  2. One custom list with custom fields
  3. One custom document library with custom fields
  4. Web parts that render both custom list and custom library
  5. For Security, setup three custom SharePoint Groups and added users
  6. Contains a Contoso Company Logo (pic)
  7. I have some ugly custom CSS applied to center various elements on the page

It looks like this:

 

Part 1: Extract the Master Site to build a remote provisioning template

  1. Download and Install PnP from: https://github.com/SharePoint/PnP-PowerShell
  2. Launch PowerShell and run the following:

Connect-PnPOnline –Url https://contoso.sharepoint.com –Credentials (Get-Credential)

Note: Authenticate using appropriate credentials

 

  1. Extract provisioning template of the master site:

get-pnpprovisioningtemplate -out c:\branding\template.xml -includesitegroups -PersistBrandingFiles

Note 1: This could take some time to run.

Note 2: I created a branding folder at the root of c:\ prior to running the above command-let.

        It should look like the following during run-time:

 

4. After Completion, I gracefully disconnect from the site by running: Disconnect-PnPOnline

Note 1: Inspecting the c:\branding directory looks like the following:

Note 2: Inspecting c:\branding\siteassets looks like the following:

Now that I have this remote provisioning template, I can reuse this several times by running Part 2 below multiple times against different top-level sites.

 

Part 2: Apply template to newly created site/s

I created a new site collection with top level site using classic\team site template.   Now I want to apply the template settings from Part 1 leveraging the SharePoint PnP PowerShell module.

  1. Launch PowerShell and run the following:

Connect-PnPOnline –Url https://contoso.sharepoint.com/sites/newsite –Credentials (Get-Credential)

Note: Authenticate using appropriate credentials

 

  1. Apply the provisioning template stored in c:\branding by running the following against template.xml:

Apply-PnPProvisioningTemplate -Path c:\branding\template.xml

Note 1:  This may take some time before it finishes

Note 2: It looks like the following during run-time:

After completion, the new site looks like the following:

With this approach, It’s easy to use new remote provisioning with PnP to get a consistent look and feel across several sites.

 

Questions and Answers

Q: If I proceed to create subsites under a site that has the provisioning template applied, will it inherit the same objects?

A: The quick answer is kind of.  It will inherit things natively by default. The following items would be inherited in this scenario:

  1. Contoso Company logo (pic)
  2. Custom Content Types
  3. Custom Site Columns
  4. Security if choice is made to inherit security from the parent site.
  5. Navigation if choice is made to inherit navigation from the parent site

The following items will not be included:

  1. Custom CSS
  2. Custom libraries
  3. Custom lists
  4. Custom fields
  5. Custom Web Parts

Note: I didn’t test with using a custom master page mainly because it’s not a recommended approach to branding SharePoint in Office 365.  This is mainly due to feature updates/upgrades of the service which could negatively impact sites bound to custom master pages.

 

Q: Is it possible to use a provisioning template created at the top-level site in a site collection and apply it to subsites?

ANo, it’s not possible because the template xml scope is set at root.  The recommended approach is to create a secondary provisioning template using the steps above for subsites and that provisioning template is used against newly created subsites.   

 

Q: If my subsites will inherit security, do I need to specify -includesitegroups when running get-pnpprovisioningtemplate?

A:  No, you would omit the -includesitegroups parameter unless you are applying unique security to a subsite.

 

This is a simple high-level scenario and I would automate this functionality by including command-lets in a PowerShell script that would both provision the site and subsequently apply the remote provisioning template.

 

References

https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps

https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/branding-and-site-provisioning-solutions-for-sharepoint

https://github.com/SharePoint/PnP-PowerShell

https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/get-pnpprovisioningtemplate?view=sharepoint-ps

https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/apply-pnpprovisioningtemplate?view=sharepoint-ps

 

Thanks,

Russ Maxwell, MSFT