Web/Site Templates in SharePoint Online Modern Pages? No problem.

Let’s imagine that we want to have a site template with a predefined design, sections, web parts on it, lists with additional fields, custom page settings etc. etc.

If you are familiar with SharePoint On-Prem versions, you probably know that we have Site Definitions and Web Templates for stuff like this. But what can we do now in SharePoint Modern Sites in combination with SharePoint Online?

We have to learn something new – we can use Site Scripts and Site Designs for some specific common steps in the creation process of our Web/Site Templates. You can see what can be done with Site Scripts on this link.
But the scope of modifying with Site Scripts is a lil’bit small, so we have to take a look into alternatives.

In the SharePoint world we have SharePoint PowerShell modules – so we could use PowerShell to modify our Modern Pages in SharePoint Online. But we want to make this happen automatically when a new Web/Site is created -> so we want to make this happen with a Web/Site Template.
That is possible only with Site Scripts and Site Designs. Fortunately we could connect our PowerShell scripts with Site Scripts and Site Designs via Microsoft Flow, which could call the Azure Function App which contains a PowerShell script.

But the PnP team went further with the PnP Provisioning Engine in their PnP PowerShell modules where you could easly specify a Web/Site Template in one XML file and put it into your PowerShell script which is called from Site Scripts via Flow.

Let’s take a look into a simple example.

We will work with SharePoint Online so you have to install the PnP PowerShell module for SharePoint Online:

Install-Module SharePointPnPPowerShellOnline

Or you have to update it to the latest version if you have already installed it:

Update-Module SharePointPnPPowerShellOnline

After that, you have to connect to one of your Modern Sites on your SharePoint Online which could be a Modern Team Site or Modern Communication Site. In my example I will work with a Modern Communication Site.

Connect-PnPOnline -Url "https://rr87.sharepoint.com/sites/TestCMS4" -Credentials (Get-Credential)

After that, you could simply add a new field into the existing SitePages library with following command:

Add-PnPField -List "SitePages" -DisplayName "Tip" -InternalName "NewsType" -Type Choice -Required -Group "News Site Columns" -AddToDefaultView -Choices "Novosti", "Dogajanja", "Dnevne novice"

This is an example of a PowerShell script for our Web/Site template in SharePoint Online which could be called from Site Scripts via Flow. But we want more so we will use the PnP Provisioning Engine.

We want to create a Site Template (like on the image below) where we want to have a two column section. 
In the left section we want to have a main News Web Part. In the right section we want to have a custom Tiles Web Part, a News Web Part for specific news categories and an Event Web Part.

For that reason, we have to create an XML file, which could be named CMS.xml.

You can read the rest of this article here.

Author: Gašper Rupnik

Software Developer and Technology Enthusiast MS, MCPS, MCSD, MCT

Leave a Reply

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