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:
- Custom Content Type
- One custom list with custom fields
- One custom document library with custom fields
- Web parts that render both custom list and custom library
- For Security, setup three custom SharePoint Groups and added users
- Contains a Contoso Company Logo (pic)
- 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
- Download and Install PnP from: https://github.com/SharePoint/PnP-PowerShell
- Launch PowerShell and run the following:
Connect-PnPOnline –Url https://contoso.sharepoint.com –Credentials (Get-Credential)
Note: Authenticate using appropriate credentials
- 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.
- Launch PowerShell and run the following:
Connect-PnPOnline –Url https://contoso.sharepoint.com/sites/newsite –Credentials (Get-Credential)
Note: Authenticate using appropriate credentials
- 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:
- Contoso Company logo (pic)
- Custom Content Types
- Custom Site Columns
- Security if choice is made to inherit security from the parent site.
- Navigation if choice is made to inherit navigation from the parent site
The following items will not be included:
- Custom CSS
- Custom libraries
- Custom lists
- Custom fields
- 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?
A: No, 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://github.com/SharePoint/PnP-PowerShell
Thanks,
Russ Maxwell, MSFT