SharePoint templates (both site and page templates) define the structure and functionality of your SharePoint environment. When trying to replicate a page's layout, identifying the template is crucial. Here are the technical approaches:
# Connect to SharePoint Online
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive
# Get Site Template
Get-PnPWeb | Select-Object WebTemplate, WebTemplateId, Configuration
# Get Page Template (for modern pages)
$page = Get-PnPClientSidePage -Identity "YourPage.aspx"
$page.PageLayoutType
using (var context = new ClientContext("https://yourtenant.sharepoint.com/sites/yoursite"))
{
context.Credentials = new SharePointOnlineCredentials(username, securePassword);
// Get Site Template
Web web = context.Web;
context.Load(web, w => w.WebTemplate, w => w.Configuration);
context.ExecuteQuery();
Console.WriteLine($"Template: {web.WebTemplate}#{web.Configuration}");
// For modern pages
var file = web.GetFileByServerRelativeUrl("/sites/yoursite/SitePages/YourPage.aspx");
var page = file.ListItemAllFields;
context.Load(page);
context.ExecuteQuery();
var layout = page["PageLayoutType"];
Console.WriteLine($"Page Layout: {layout}");
}
// Get Site Template
GET https://yourtenant.sharepoint.com/sites/yoursite/_api/web?$select=WebTemplate,Configuration
// Get Page Template (modern)
GET https://yourtenant.sharepoint.com/sites/yoursite/_api/web/getfilebyserverrelativeurl('/sites/yoursite/SitePages/YourPage.aspx')/listitemallfields?$select=PageLayoutType
- STS#0: Team site (classic)
- GROUP#0: Modern Team site
- BDR#0: Document Center
- PageLayoutType: Article: News page layout
- PageLayoutType: Home: Home page layout
If you're getting null values for modern pages, ensure you have proper permissions and verify the page is actually a modern page (classic wiki/web part pages require different approaches). For publishing pages, check the PublishingPageLayout
field instead.
SharePoint templates define the structure and functionality of sites and pages. There are two main types:
- Site Templates (e.g., STS#0 for Team Site, BLOG#0 for Blog)
- Page Templates (used in modern and classic pages)
For a quick check without code:
- Navigate to Site Settings
- Under "Site Actions", click "Save site as template"
- The template ID appears in the URL (Template=STS#0)
Here's a PowerShell script using PnP PowerShell:
# Connect to SharePoint
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive
# Get site template
$web = Get-PnPWeb
$web.WebTemplate + "#" + $web.Configuration
For modern page templates, use this C# code:
using (var ctx = new ClientContext("https://yourtenant.sharepoint.com"))
{
ctx.Credentials = new SharePointOnlineCredentials(username, securePassword);
var page = ctx.Web.GetFileByServerRelativeUrl("/sites/yoursite/SitePages/home.aspx");
ctx.Load(page, f => f.Properties);
ctx.ExecuteQuery();
Console.WriteLine(page.Properties.FieldValues["ClientSideApplicationId"]);
}
For classic publishing pages, inspect the Page Layout:
$page = Get-PnPFile -Url "/sites/publish/SitePages/home.aspx" -AsListItem
$page["PublishingPageLayout"]
Template | ID |
---|---|
Team Site | STS#0 |
Communication Site | SITEPAGEPUBLISHING#0 |
Blog | BLOG#0 |