How to save and deploy SharePoint page templates

SharePoint page templates are pre-designed pages that can be used as a starting point for creating new content. They often include pre-defined layouts, text, web parts, and can save time and effort in the content creation process.

Page templates can be customized and modified to fit the specific needs of a site collection, however is not possible to share them across different sites. In this article I’m sharing a solution to save your page templates and deploy them in different site collections.

Save and deploy SharePoint pages as templates

💎 Pro Tip!

Before saving the page templates I recommend you to go through each one of them and check if there are images used in the template stored in the site collection. If that is the case I recommend you to host any template images in the organization asset library this way you guarantee that all the users in the new site collection will be able to see the images.
If you are not familiar with this concept you can read more about it here.

In order to accomplish the steps described in this article you must install the latest version of the PnP PowerShell module, more information about how to do it can be found here.

Save SharePoint page templates using PnP PowerShell

  1. Start by opening the PowerShell console in your computer
  2. Copy the script below and update the variables $siteCollection, $templateName and $saveTemplateLocation
    $siteCollection = ""
    $saveTemplateLocation = "C:\Users\JOAO\Desktop\"
    $templateName = "template"
    Connect-PnPOnline -Url $siteCollection -Interactive
    $siteTemplate = Get-PnPSiteTemplate -IncludeAllClientSidePages -Handlers Pages,PageContents -OutputInstance 
    $pagesTemplate = New-PnPSiteTemplate
    foreach($page in $siteTemplate.ClientSidePages)
         if($page.PromoteAsTemplate -eq $true)
    Save-PnPSiteTemplate -Template $pagesTemplate -Out ("{0}{1}.xml" -f $saveTemplateLocation, $templateName)
  3. Execute the script and wait for it to finish, the process may take some time depending on the number of pages you have in the site collection

Save and deploy SharePoint pages as templates

Once the process finishes you will get an XML file containing the definition of all the templates copied from the site collection.

Deploy SharePoint page templates using PnP PowerShell

  1. With the PowerShell console open, copy the script below
    $siteCollection = ""
    $templateFileLocation = "C:\Users\JOAO\Desktop\template.xml"
    Connect-PnPOnline -Url $siteCollection -Interactive
    Invoke-PnPSiteTemplate -Path $templateFileLocation
  2. Update the variables $siteCollection and $templateFileLocation with your own values
  3. Execute the script and wait for it to finish

To check the success of the deployment, go to the site collection where you just installed the templates, create a new page and at the top you should have a section Saved on this site as shown in the following picture with all your templates.

Save and deploy SharePoint pages as templates

No comments yet

Leave a Reply

I've been working with Microsoft Technologies over the last ten years, mainly focused on creating collaboration and productivity solutions that drive the adoption of Microsoft Modern Workplace.

%d bloggers like this: