I have created a news post and saved it as template on a modern communication site. Is there an option to reuse the template while creating news posts on the subsites as well? Any pointers on this is appreciated. Thnaks


It is possible to just copy the Template files from /SitePages/Templates folder to all subsites.

However, there are some limitations

  • We must manually create at least one page template on the target subsite. This will trigger some internal process that will make tempaltes work. Otherwise, your copied templates will remain ignored. Good news is that you need to do it only once per subsite.
  • You need PowerShell PnP version: 3.12.19 or later

PowerShell PnP Code to copy all site templates from the root site to all subsite within site collection

    # Need new PnP version: 3.12.19 or later
    Install-Module SharePointPnPPowerShellOnline 

    # Make sure PnP version is 3.12.19 or later
    Get-Module SharePointPnPPowerShellOnline -ListAvailable

    # Ensure 'Templates' folder exists on all sub sites: 
    Get-PnPSubWebs -Recurse | % {Resolve-PnPFolder -SiteRelativePath "SitePages/Templates" -Web $_ }

    # Get All Page Templates:
    $PageTemplates = Get-PnPFolderItem -FolderSiteRelativeUrl '/SitePages/Templates'

    #Download all Page templates:
    $PageTemplates | % { Get-PnPFile -Url "/SitePages/Templates/$($_.Name)"  -Filename $_.Name -AsFile }

    # Upload Page templates to all subsites of the current site collection
    $subwebs = Get-PnPSubWebs -Recurse
    foreach ($subweb in $subwebs){
        Write-host Processing $subweb.Title
        Get-ChildItem -Filter "*.aspx" | % { Add-PnPFile -Web $subweb -Path "$(Get-Location)\$($_.Name)" -Folder "\SitePages\Templates" -Publish }           

        # TODO:
        # Subsite needs at least one Page tempalte saved manually. Otherwise our moved tempaltes won't show up.

enter image description here

enter image description here

enter image description here

|improve this answer|||||

The news post templates are stored in the current site "Site Pages" library, we cannot use this template on subsites.

|improve this answer|||||

In case someone wants to modify the above code to move templates to another site collection, try this :

$rootSite = "https://<site>.sharepoint.com"
$sourceContext = Connect-PnPOnline -Url $rootSite -UseWebLogin

# Get All Page Templates:
$PageTemplates = Get-PnPFolderItem -FolderSiteRelativeUrl '/SitePages/Templates'  
  -Connection $sourceContext

#Download all Page templates:
$PageTemplates | % { Get-PnPFile -Url "/SitePages/Templates/$($_.Name)" -Connection 
    $sourceContext  -Path c:\temp  -Filename $_.Name -AsFile }

$destSite = "https://<site>.sharepoint.com/sites/<site>"
$destContext = Connect-PnPOnline -Url $destSite -UseWebLogin

# Ensure 'Templates' folder exists on new Site Collection 
Resolve-PnPFolder -SiteRelativePath "SitePages/Templates" -Connection $destContext

# Upload Page templates to new site collection
$PageTemplates | % { Add-PnPFile -Connection $destContext -Path "C:\temp\$($_.Name)" - 
   Folder "SitePages\Templates" }

# Create one template to trigger the availability of all the migrated templates
# Assumes that you already the default page named 'Home.aspx' , which all new Site 
# Collection should have by default
$page = Get-PnPClientSidePage -Identity "Home.aspx"

# Save the page as template to be reused later-on

Remove-PnPFile -ServerRelativeUrl 
   "/sites/training/sitepages/templates/Dummy_Template.aspx" -Force
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.