SharePoint Site Design and Site Script

Why Site Design & Site Script

Every business organization required customization and for that, a custom site template is required so that some level of consistency can be maintained when your organization users create new sites. This customization can be anything like – Apply a custom theme that matches your corporate branding, organization logo, custom list and libraries, custom actions, and many more.

For all this, a custom site template is required which can be used to create a new site collection with all these customizations same can be achieved using site design and site script in SharePoint online.

Note: SharePoint Site design and Site script only work on the online model it is not applicable for the SharePoint on-premises model.

What is Site design

Site design is a template, which can be used to provision new SharePoint modern sites with your own custom configuration. These configurations are called actions and these actions are executed one by one when you provision a site using custom site design.

SharePoint online offers only two types of templates so a new site design can be created on top of these two templates –

1. Team Site – This has a template ID 64.
2. Communication Site – this has a template ID 68.

How to create a site design

To create a Site design first need to write a site script. The site script is nothing but a JSON file where a set of actions are written in order and these actions are executed when a site is created.

Note: Each individual action is called a verb in the site script.

In this sample, I am using visual studio code to write the site script you can use a notepad as well to write a site script.

Steps to create a site script that creates a new site design (template) –

1. Open visual studio code and go to file a new menu and create a new file.
2. Write a site script and add action one by one according to your need. likewise, I have added the below script.

3. Now save this file with any name and .json extension in your local drive. Let say you save this as demositescript.json.

Here in this site script, I have done the below actions –

1.ApplyTheme  – Applying one custom theme named “Custom Branding”. Make sure this theme should exist in your tenant otherwise this action is not applied.

2.CreateSPList – Here I am created one custom List template 100 named “Customer Feedback” also set its description in subactions.

3.CreateSpList – this is an existing document Library I am only updating its description. You can create a document library using this verb or action with template ID 100.

4.AddNavLink – I am adding one navigation Link in quick launch and its title is “Microsoft”.

5.SetSiteExternalSharingCapability – A required parameter to specify the sharing option for the site collection.

I have added a total of five actions in this site design and site script but SharePoint provides below a set of actions available that you can use to create your SharePoint site design and site script –

Available actions to be used in site script:

  • Applying a theme
  • Creating a new list or library (or modifying the default one created with the site)
  • Creating site columns, content types, and configuring other list settings
  • Set site branding properties like navigation layout, header layout, and header background
  • Setting a site logo – This will not work on team sites (template Id 64). It only works with communication sites (template Id 68).
  • Adding navigation links to quick launch or hub navigation.
  • Triggering a Power Automate flow.
  • Installing a deployed solution from the app catalog.
  • Setting regional settings for the site.
  • Adding principals (users and groups) to SharePoint roles.
  • Setting external sharing capability for the site.

Therefore, we are done we site script creation and now we have to apply this site script to SharePoint online.

How to add a site design and site script

There are two different ways to add this site design and site script to SharePoint online tenant –

  1. Using PowerShell Script
  2. Rest API

I am using PowerShell script and the “Add-SPOSiteDesign” command is used to apply the same-

Copy the above script in one .ps1 file and make sure you update your SharePoint admin center URL and run the script once this script will execute successfully a new site design is added to SharePoint and you can check the same by login on the SharePoint Online admin center.

Now to use can use this site design to provision new site collections.

let’s create one site collection using this site design-

  1. Choose a site design “Custom Team Site” in the dropdown.
  2. Enter the site name of your choice and fill in all the required parameters.
  3. Click on the finish button to provision a new site using this site design.
  4. Now open the newly created sites and click on the gear icon from the top right corner.
  5. Then click on the “Site design” link it shows all actions that we have added in the site script above and the same was applied to the provisioned site.

sharepoint site collection using site design and site script

If you have already created some site collection using other templates this new site design can also be applied to that site collection as well.

I hope you understand SharePoint site design and site script and now you able to develop the same on your own.

Happy Learning!