Provision SharePoint Site using Custom Template with PnP JS

Ahamed Fazil Buhari
 
Senior Developer
September 27, 2018
 
Rate this article
 
Views
4049

Hi,

In this article we will see how to provision SharePoint site using PnP JS and more we can provision by our own custom site template. For this we need to know the GUID of your custom template, there are various way to get GUID of site template and one of the easy way is shown below,

I just moved to the page where we can manually create subsite (https://<sharepointURL>/_layouts/15/newsbweb.aspx ). Right click on the custom template name and select Inspect from your browser so that you can see the source of the page and from that we can get GUID of your custom template.

 

image

Once we get the template ID, we need to call below PnP code to provison site and in the parameter we need to provide values for following options –

Site Title, URL, description, template name or ID, lang, permission Inheritance.

 import pnp from "sp-pnp-js/lib/pnp";
 
 pnp.sp.web.webs
         .add(
           "New Sub Site",
           "newsite",
           "Description for the new Site",
           "{1BDB855A-CC85-4AF4-8C58-BCDD7F02xxxx}",
           1033,
           true
         )
         .then(function(result) {
           if (result.data.Created) {
             alert("Site created successfully");
           }
         })
         .catch(e => {
           console.log("eeerrr", e);
         });
 

 

 

image

Happy Coding

Ahamed

Author Info

Ahamed Fazil Buhari
 
Senior Developer
 
Rate this article
 
Ahamed is a seasoned Senior Developer with strong expertise in React, TypeScript, Next.js, and Redux. He also has deep experience across the Microsoft ecosystem, including Azure, Microsoft 365, SPFx, and ...read more
 

Leave a comment