Problem Statement
In this article, I would like to explain this: If the user makes any changes to duplicate page, how to publish the duplicate client side pages to the original page into same site pages library within the same site collection.
As a developer, we have a couple of options to duplicate the page into another modern site collection library or different folder strucutre, but there is no way to copy the pages within the same modern site collection sites library within the same folder structure.
Prerequisite Steps
Let's create a page and add exisitng below control, or user can add any other available controls. This is just for demo purposes.
- SharePoint Online PnP PowerShell Overview here
- Browse the exisitng pages
Home Page looks like this,
Duplicate Page looks like this with changes,
- Add new control
- Modify the pages control layout
Approach Overview
Key steps to publish duplicate client side page with changes to original Modern Site Collection Site Pages into Same Library Folder.
- Use PnP Online to connect to SharePoint Online Modern Site
- Export PnP Client Side Pages Command export pages with PnP Provisioning Template
- Store it locally.
- Apply PnP Provisioning Template store it with different name.
- try
- {
-
- $srcUrl = "https://mittal1201.sharepoint.com/sites/commsitehub"
- Connect-PnPOnline -Url $srcUrl
-
- $SourcePageName = "home_duplicate"
- $TargetPageName = "home"
-
- $tempFile = 'C:\CsharpCorner\'+ $SourcePageName +'.xml'
- Export-PnPClientSidePage -Force -Identity $SourcePageName -Out $tempFile
-
- $con = Get-Content $tempFile
- $sourcepage=$SourcePageName +".aspx"
- $targetpage=$TargetPageName +".aspx"
-
- $con | % { $_.Replace($sourcepage,$targetpage) } | Set-Content $tempFile
- Apply-PnPProvisioningTemplate -Path $tempFile
- write-host -ForegroundColor Magenta "Page reverted with name of " $targetpage
-
-
- }
- catch {
- Write-Host - ForegroundColor Red 'Error ', ':'
- $Error[0].ToString();
-
- }
Save and run this script.
OutPut Steps
Applying template to client side pages
Export-PnPClientSidePage Cmdlets applying the PnP Provisioning template and export ".xml" file into shared locaiton. Cmdlets referece can be find
here
Creation of client side pages
Apply-PnPProvisioningTemplate cmdlets will create a new page within the same library from download or exported ".xml" file with provided name i.e. pagename _ duplicate
Cmdlets referece can be find
here
Final Duplicate Page Outcome
Browse the url; i.e., original page. New Client Side Page will be available with all configuration and controls.
I hope you have enjoyed and learned something new in this article. Thanks for reading and stay tuned for the next article.