Vue normale

Il y a de nouveaux articles disponibles, cliquez pour rafraîchir la page.
À partir d’avant-hierFlux principal

Set a page template as default page template in SharePoint Online

SharePoint Online is a powerful collaboration and content management platform that allows organizations to create and manage sites for various purposes. One of the key features that enhances site design and improves user experience is the use of Page Templates. In this blog post, we will delve into what are page templates in SharePoint online and how to set a default page template for a SharePoint site.

What are Page Templates in SharePoint?

Page templates in SharePoint Online are pre-designed layouts or structures that provide a consistent and standardized format for creating site pages within a site. They serve as a starting point for designing and organizing content on SharePoint pages, ensuring a cohesive look and feel across the site.

Page templates can include a variety of elements such as placeholders for text, images, web parts, page sections, and more. By using page templates, users can quickly create new pages with a predefined structure and layout, saving time and effort while maintaining visual consistency.

Setting a Default Page Template for a SharePoint Site

When users try to create new site pages from SharePoint site home page, the default selected template in the Page Templates pane is Blank. If users don’t select a different template, the blank template will be used for their new page.

If you prefer to have another custom page template be the default selection for your SharePoint site while creating new site pages, follow one of the methods given below:

Using SharePoint User Interface

Follow below steps to set a default page template for your SharePoint online site from SharePoint UI:

1. Go to home page of your SharePoint online site.

2. Click on New from page command bar and select Page:

Open Page templates pane from SharePoint online site home page
Open Page templates pane from SharePoint online site home page

3. Click on vertical ellipses at the bottom right side of the template you want, and then select Set default selection:

Set default selection of page template for SharePoint online site
Set default selection of page template for SharePoint site

4. Click OK from Changing default selection confirmation popup.

Note: When you change the default selection in the page templates pane, it will be changed for all users in the SharePoint site.

Using PnP PowerShell

You can use below PnP PowerShell script to set a page template as default page template for SharePoint online site:

# SharePoint online site URL
$siteUrl = Read-Host -Prompt "Enter your SharePoint site URL (e.g https://contoso.sharepoint.com/sites/work)"

# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive

# Get page template details and Unique ID
$page = Get-PnPFile -Url "/sites/work/SitePages/Templates/PlainHeaderNoComments.aspx" -AsListItem

# Set a page template as default page template for SharePoint online site
Set-PnPPropertyBagValue -Key DefaultNewPageTemplateId -Value $page["UniqueId"]

# Disconnect SharePoint online connection
Disconnect-PnPOnline

You may get error like below while executing above PnP PowerShell script if custom scripts are not enabled for your SharePoint site:

Set-PnPPropertyBagValue: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) Site might have NoScript enabled, this prevents setting some property bag values.

In that case, you have to first enable the custom scripts for your SharePoint site by following: Allow use of custom scripts in SharePoint Online using PowerShell.

Using CLI for Microsoft 365

Use below CLI for Microsoft 365 script to set a page template as default page template for SharePoint online site:

# Get Credentials to connect
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
    m365 login
}

# SharePoint online site URL
$siteUrl = Read-Host -Prompt "Enter your SharePoint site URL (e.g https://contoso.sharepoint.com/sites/work)"
 
# Get page template details and Unique ID
$page = m365 spo file get --webUrl $siteUrl --url '/sites/work/SitePages/Templates/PlainHeaderNoComments.aspx' | ConvertFrom-Json

# Set a page template as default page template for SharePoint online site
m365 spo propertybag set --webUrl $siteUrl --key DefaultNewPageTemplateId --value $page.UniqueId

If custom scripts are not enabled for your SharePoint site, above CLI for Microsoft 365 script will throw error like:

Error: Site has NoScript enabled, and setting property bag values is not supported

In that case, you have to first enable the custom scripts for your SharePoint online site by following: Allow use of custom scripts in SharePoint Online using PowerShell.

Conclusion

Page templates in SharePoint online provide a valuable tool for enhancing site design and improving user experience. By setting a default page template, organizations can establish a consistent and standardized format for creating web pages within their SharePoint sites. This not only saves time but also ensures a cohesive and professional look across the site. By leveraging page templates, organizations can effectively showcase their content while maintaining their branding and style guidelines.

Learn more

Allow use of custom scripts in SharePoint Online using PowerShell

SharePoint online is a powerful platform that allows users to create and manage websites and content, collaborate with others, and more. However, SharePoint out-of-the-box features may not always meet the specific needs of your organization.

Fortunately, SharePoint online allows the use of custom scripts, which can be used to enhance the platform’s functionality and customize it to your specific needs.

When you allow the use of custom scripts in SharePoint online sites, users gain access to a wide range of features and functionalities. Here are some of the key capabilities that become available:

  • Web Parts: Users can use classic experience web parts like Script Editor, Content Editor (and lot more) using which they can create custom web parts using client-side scripting languages like JavaScript or TypeScript.
  • Use of Save Site as Template, Save document library as template, etc. features in SharePoint.
  • Use of Solution Gallery, Theme Gallery, Sandbox solutions, HTML Field Security, etc. settings in SharePoint sites.
  • Uploading files types that are blocked by default like .asmx .ascx .aspx .htc .jar .master .swf .xap .xsf

Let’s see how you can allow or prevent use of custom scripts in SharePoint Online sites using different PowerShell tools:

Using SharePoint Online PowerShell

Use below SharePoint Online PowerShell script to check if custom scripts are enabled or disabled for a SharePoint online site and then to allow use of custom scripts for specified SharePoint online site:

# SharePoint online admin center URL
$adminCenterUrl = "https://contoso-admin.sharepoint.com/"

# SharePoint online site URL
$siteUrl = "https://contoso.sharepoint.com/sites/SPConnect"

# Connect to SharePoint online admin center
Connect-SPOService -Url $adminCenterUrl

# Allow custom scripts on SharePoint online site
Set-SPOSite $siteUrl -DenyAddAndCustomizePages 0

# Verify that custom scripts are enabled on SharePoint online site
Get-SPOSite $siteUrl | select DenyAddAndCustomizePages

Using PnP PowerShell

You can use below PnP PowerShell script to allow or prevent use of custom scripts in SharePoint online site:

# SharePoint online site URL
$siteUrl = "https://contoso.sharepoint.com/sites/SPConnect"

# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive

# Allow custom scripts on SharePoint online site
Set-PnPSite -NoScriptSite $false

# Prevent custom scripts on SharePoint online site
Set-PnPSite -NoScriptSite $true

Using CLI For Microsoft 365

Use below CLI for Microsoft 365 script to allow use of custom scripts in SharePoint online site collection:

# SharePoint online site URL
$siteUrl = "https://contoso.sharepoint.com/sites/SPConnect"

# Connect to SharePoint online tenant
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
    m365 login
}

# Allow custom scripts on SharePoint online site collection
m365 spo site set --url $siteUrl --noScriptSite $false

Conclusion

Enabling custom script support for SharePoint online sites can enhance the platform’s functionality and enable users to customize site to their specific needs. However, it’s important to carefully consider the potential security risks before enabling this feature, check: security considerations of allowing custom scripts in SharePoint.

Learn more

❌
❌