Understanding Site Design and Site Scipt in SharePoint

Introduction

In SharePoint Online, "Site Design" and "Site Scripts" are tools that allow administrators and developers to automate and apply consistent configurations, branding, and content structures to SharePoint sites.

  1. Site Design: A Site Design is essentially a template or blueprint for a SharePoint site. It defines the configuration settings, design elements, and actions to be applied when creating or modifying a site. Site Designs can include actions such as applying themes, adding lists or libraries, configuring site permissions, and more.
  2. Site Scripts: Site Scripts are JSON files that define the individual actions to be performed as part of a Site Design. These actions can range from simple tasks like creating a list to more complex actions such as applying a custom theme or installing custom solutions. Site Scripts are reusable and can be combined to create Site Designs tailored to specific organizational needs.

Create a Site Design in SharePoint Online

To create a Site Design in SharePoint Online, you can follow these general steps.

  1. Prepare Your Site Design: Determine the configuration settings, design elements, and actions you want to include in your Site Design. This could involve deciding on themes, lists and libraries, site structure, permissions, and any other customizations you want to apply.
  2. Create Site Scripts: Site Designs are built using Site Scripts, which are JSON files that define the actions to be performed. You can create Site Scripts using a text editor or JSON editor. Each Site Script represents a specific action or set of actions to be applied to the site.
  3. Combine Site Scripts into a Site Design: Once you have created your Site Scripts, you need to combine them into a single Site Design. You can do this using PowerShell or by using the PnP Powershell. The Add-PnPSiteDesign cmdlet is used to create a new Site Design, and you can specify which Site Scripts to include in the design.

Example of creating a Site Design using PowerShell

Here's a basic example of creating a Site Design using PowerShell.

# Connect to SharePoint Online
Connect-PnPOnline -Url https://yourtenant.sharepoint.com -Interactive

# Create a new Site Script (replace the JSON with your own script)
$siteScript = @"
{
    "actions": [
        {
            "verb": "createSPList",
            "listName": "MyDocuments",
            "templateType": 101,
            "subactions": [
                {
                    "verb": "setDescription",
                    "description": "This is a custom document library."
                }
            ]
        }
    ]
}
"@

# Save the Site Script
$siteScriptId = Add-PnPSiteScript -Title "Custom Document Library" -Description "A more detailed description" -Content $siteScript

# Create a new Site Design and add the Site Script
Add-PnPSiteDesign -Title "Custom Site Design" -SiteScriptIds $siteScriptId.Id -WebTemplate CommunicationSite -Description "This is a custom site design for SharePoint Online" 

This script creates a new Site Script defining the creation of a custom document library, then creates a Site Design and associates the Site Script with it. Finally, you can apply this Site Design to SharePoint sites as needed.

Apply site design in SharePoint Online

Now, you can apply this site design to your new site or existing site. Here’s a step-by-step guide on how to do it.

  • Visit your SharePoint site to which you want to apply site design à Then Click on settings à Apply Site Template.
  • Here you’ll able to see your custom site design In From Your organization section. Click on it.
    Select Template
  • Now you we’ll see use template button this will apply our created site design to current site.
    Use template

Conclusion

Site Designs and Site Scripts in SharePoint Online offer a streamlined way to automate site provisioning and ensure consistency across your environment. By creating custom Site Designs and applying them to new or existing sites, organizations can save time, enhance collaboration, and maximize the value of their SharePoint investment.