none
How to create page template by using PnP provisioning in SharePoint online RRS feed

  • Question

  • Can someone please advise me how to create pageTemplate by using PnP provisioning script creating new modern pages with this page template
    Wednesday, September 18, 2019 4:22 PM

Answers

  • Hi Rajesh,

    Please use the PnP PowerShell script below to get the pageTemplate.aspx page to the local and add new modern page base on this page.

    $SiteUrl="https://tenant.sharepoint.com/sites/dennis"
    $LocalPath="c:\temp\"
    $PageName="test.aspx"
    $NewPageName="NewPage.aspx"
    
    $Folder="SitePages"
    $PageUrl=$Folder+"/"+$PageName
    Connect-PnPOnline -Url $SiteUrl
    Get-PnPFile -Url $PageUrl -Path $LocalPath -FileName $PageName -AsFile -Force
    Add-PnPFile -Path $LocalPath$PageName -Folder $Folder -NewFileName $NewPageName

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, September 20, 2019 5:12 AM
    Moderator

All replies

  • use the below command for creating a new provisioning template object.

    Connect-PnPOnline -Url https://contoso.sharepoint.com -Credentials (Get-Credential)
    
    $template = New-PnPProvisioningTemplate

    Below article for your reference:

    https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/new-pnpprovisioningtemplate?view=sharepoint-ps

    Thanks & Regards,


    sharath aluri

    Thursday, September 19, 2019 1:08 AM
  • But how to create particular page template and create new pages with the same template?

    Its not about site template its about page template

    Thursday, September 19, 2019 1:13 AM
  • Try checking from a below article to build a custom SharePoint page template.

    https://social.technet.microsoft.com/wiki/contents/articles/33111.build-a-custom-sharepoint-page-template-to-display-site-columns.aspx

    Thanks & Regards,


    sharath aluri

    Thursday, September 19, 2019 2:11 AM
  • I am talking about using PnP provisioning
    Thursday, September 19, 2019 4:25 AM
  • I exported the existing page as page template by using PnP provisiong script as shown in below

    Export-PnPClientSidePage -Identity "test.aspx" -Out "pageTemplate.xml"

    How can i apply this "pageTemplate.xml" to new modern page by using PnP provisioning.

    Thursday, September 19, 2019 4:35 AM
  • Hi Rajesh,

    Please check all the PnP PowerShell cmdlets in the link below, unfortunately, there is not a cmdlet can create a modern page base on the page template(Using Export-PnPClientSidePage cmdlet to get it)  currently.

    https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/?view=sharepoint-ps

    As a workaround, we can use the PnP PowerShell script below to create a new modern page base on the exist modern page.

    $SiteUrl="https://tenant.sharepoint.com/sites/dennis"
    $LocalPath="c:\temp\"
    $PageName="test.aspx"
    $NewPageName="NewPage.aspx"
    
    $Folder="SitePages"
    $PageUrl=$Folder+"/"+$PageName
    Connect-PnPOnline -Url $SiteUrl
    Get-PnPFile -Url $PageUrl -Path $LocalPath -FileName $PageName -AsFile -Force
    Add-PnPFile -Path $LocalPath$PageName -Folder $Folder -NewFileName $NewPageName

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.



    Thursday, September 19, 2019 7:24 AM
    Moderator
  • I totally agree with Dennis there is no PnP command we have to create page template for modern pages.
    Regards,
    Krishna
    Thursday, September 19, 2019 12:05 PM
  • But how we can apply this script if the pageTemplate saves under sitepages/Templates as pageTemplate.aspx?

    Do we any other option to create modern pages automatically by taking reference from pageTemplate?

    Friday, September 20, 2019 5:04 AM
  • Do we any other option to create modern pages automatically by taking reference from pageTemplate?
    Friday, September 20, 2019 5:04 AM
  • Hi Rajesh,

    Please use the PnP PowerShell script below to get the pageTemplate.aspx page to the local and add new modern page base on this page.

    $SiteUrl="https://tenant.sharepoint.com/sites/dennis"
    $LocalPath="c:\temp\"
    $PageName="test.aspx"
    $NewPageName="NewPage.aspx"
    
    $Folder="SitePages"
    $PageUrl=$Folder+"/"+$PageName
    Connect-PnPOnline -Url $SiteUrl
    Get-PnPFile -Url $PageUrl -Path $LocalPath -FileName $PageName -AsFile -Force
    Add-PnPFile -Path $LocalPath$PageName -Folder $Folder -NewFileName $NewPageName

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, September 20, 2019 5:12 AM
    Moderator
  • I got the below error while executing the above scripts even though i  have full control permissions of the site.

    Add-PnPFile : Access denied. You do not have permission to perform this action or access this resource.
    At line:10 char:1
    + Add-PnPFile -Path $LocalPath$PageName -Folder $Folder -NewFileName $N ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : WriteError: (:) [Add-PnPFile], ServerUnauthorizedAccessExcep

    Friday, September 20, 2019 5:46 AM
  • Now i am able to execute by adding the below command.

    Set-SPOSite -Identity $SiteUrl -DenyAddAndCustomizePages $false

    Thanks Dennis

    Do we any other option to create modern pages automatically by taking reference from pageTemplate?

    Friday, September 20, 2019 6:03 AM
  • Hi Rajesh,

    It seems not other SharePoint API in currently to create modern pages automatically from a template.

    https://docs.microsoft.com/en-us/dotnet/api/officedevpnp.core.pages.clientsidepage?view=sharepointpnpcoreonline-2.18.1709.0

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, September 20, 2019 8:12 AM
    Moderator
  • I got the below pageTempalte XML file after executing the below PnP command

    Export-PnPClientSidePage -Identity "Template.aspx" -Out "page-template.xml"

    ---------------------------------------------------------------------------------

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2019/03/ProvisioningSchema"> <pnp:preferences generator="OfficeDevPnP.Core, Version=3.12.1908.0, Culture=neutral, PublicKeyToken=5e633289e95c321a" style="display:block;font-family:Verdana;font-size:13.33px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:700;padding-" xmlns:pnp="http://schemas.dev.office.com/PnP/2019/03/ProvisioningSchema"><pnp:Preferences Generator="OfficeDevPnP.Core, Version=3.12.1908.0, Culture=neutral, PublicKeyToken=5e633289e95c321a"/></pnp:preferences> <pnp:templates id="CONTAINER-" style="display:block;font-family:Verdana;font-size:13.33px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:700;padding-" xmlns:pnp="http://schemas.dev.office.com/PnP/2019/03/ProvisioningSchema"><pnp:Templates ID="CONTAINER-"> <pnp:provisioningtemplate scope="Undefined" style="display:block;padding-" version="0"><pnp:ProvisioningTemplate Scope="Undefined" Version="0"> <pnp:clientsidepages style="display:block;padding-"><pnp:ClientSidePages> <pnp:clientsidepage overwrite="true" pagename="Template.aspx" promoteasnewsarticle="false" promoteastemplate="false" style="display:block;padding-" title="Template"><pnp:ClientSidePage Title="Template" Overwrite="true" PromoteAsTemplate="false" PromoteAsNewsArticle="false" PageName="Template.aspx"> <pnp:sections style="display:block;padding-"><pnp:Sections> <pnp:section order="1" style="display:block;padding-" type="OneColumn"><pnp:Section Type="OneColumn" Order="1"> <pnp:controls style="display:block;padding-"><pnp:Controls> <pnp:canvascontrol column="1" controlid="1c534d56-7a93-497f-b789-d15c07d47132" jsoncontroldata="{"id": "1c534d56-7a93-497f-b789-d15c07d47132", "instanceId": "bf91254f-88ab-46f0-b4de-d603a492b556", "title": "Process", "description": "Process description", "dataVersion": "1.0", "properties": {"description":"Process"}, "serverProcessedContent": {"htmlStrings":{},"searchablePlainTexts":{},"imageSources":{},"links":{}}, "dynamicDataPaths": {}, "dynamicDataValues": {}}" order="1" style="display:block;padding-" webparttype="Custom"><pnp:CanvasControl Order="1" Column="1" ControlId="1c534d56-7a93-497f-b789-d15c07d47132" JsonControlData="{"id": "1c534d56-7a93-497f-b789-d15c07d47132", "instanceId": "bf91254f-88ab-46f0-b4de-d603a492b556", "title": "Process", "description": "Process description", "dataVersion": "1.0", "properties": {"description":"Process"}, "serverProcessedContent": {"htmlStrings":{},"searchablePlainTexts":{},"imageSources":{},"links":{}}, "dynamicDataPaths": {}, "dynamicDataValues": {}}" WebPartType="Custom"/></pnp:canvascontrol> </pnp:Controls></pnp:controls> </pnp:Section></pnp:section> </pnp:Sections></pnp:sections> <pnp:header alternativetext="" authorbyline="[]" authorbylineid="-1" authors="[]" layouttype="FullWidthImage" serverrelativeimageurl="{site}/SiteAssets/79235-TopBackground.PNG" showpublishdate="false" showtopicheader="false" style="display:block;padding-" textalignment="Center" topicheader="" type="Custom"><pnp:Header Type="Custom" AuthorByLineId="-1" AuthorByLine="[]" Authors="[]" AlternativeText="" TopicHeader="" ShowPublishDate="false" ShowTopicHeader="false" TextAlignment="Center" LayoutType="FullWidthImage" ServerRelativeImageUrl="{site}/SiteAssets/79235-TopBackground.PNG"/></pnp:header> <pnp:security style="display:block;padding-"><pnp:Security> <pnp:breakroleinheritance clearsubscopes="false" copyroleassignments="false" style="display:block;padding-"><pnp:BreakRoleInheritance ClearSubscopes="false" CopyRoleAssignments="false"/></pnp:breakroleinheritance> </pnp:Security></pnp:security> </pnp:ClientSidePage></pnp:clientsidepage> </pnp:ClientSidePages></pnp:clientsidepages> </pnp:ProvisioningTemplate></pnp:provisioningtemplate> </pnp:Templates></pnp:templates> </pnp:Provisioning>

    -----------------------------------------------------------------------------------Is there any possibility i can create the modern pages by using the above page-template.xml file by scripts or PnP or flows?


    Friday, September 20, 2019 8:42 AM
  • Hi Rajesh,

    Unfortunately, there is not an API to create the modern pages by using the template.xml file in currently.

    Best Regards,

    Dennis 


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, September 20, 2019 8:48 AM
    Moderator
  • Hi Dennis thanks for your immediate reply on this and your support is really appreciated.

    Can you help on the below requirement i am sturggling to get child child child nodes by recursive.

    I have the same XML as shown in below 

                   

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <Processes>
     <Process>
          <Id>ABC123</Id>
         <ParentId>123</ParentId>
         <SubProcesses>
             <Process>
           <Id>DEFABC</Id>
                          <ParentId>ABC123</ParentId>
         <SubProcesses>
                               <Process>
            <Id>GHIDEF</Id>
                                          <ParentId>DEFABC</ParentId>
             .... 
    </process>
    </SubProcesses>
    </process>
    </SubProcesses>
     </Process>
    </Processes>

    I have list having columns "Id" & "ParentId" how can i read the xml including all the child nodes might be recursive or check length > 0 and import all the data into "List" may be either "PnP" scripts or "PowerShell" or any?

    Friday, September 20, 2019 8:53 AM
  • Hi Rajesh,

    If you have new question, I would suggest you post it in a new thread, it would make others easier to focus on one question in one single thread and it will benefit other community members who stuck with the same question.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, September 20, 2019 9:06 AM
    Moderator
  • Any possibility we can execute this command with out having local path "
    $LocalPath="c:\temp\"
    "
    Tuesday, September 24, 2019 11:18 AM
  • Hi Rajesh,

    We have to use this local path, we need use a folder to store the file download from SharePoint Online.

    If you don't have this folder, we can use the PowerShell below to create it.

    New-Item -Path "c:\" -Name "temp" -ItemType "directory"

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, September 25, 2019 7:11 AM
    Moderator
  • If i want to execute the script on production or testing environment.

    In that environment i dont know whether "C:\" drive existed there or not.

    How can we overcome this?

    Monday, September 30, 2019 5:30 AM
  • Hi Rajesh,

    We can use the PowerShell below to get the drive.

    $drive=get-wmiobject -class win32_logicaldisk -filter "DriveType=3"|select DeviceID

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, September 30, 2019 6:54 AM
    Moderator
  • Thanks Dennis for your immediate reply.

    I am trying to create the modern pages by using page template as mentioned above.

    Now i want to create the navigation based on the names of pages under "Site Pages".

    when i execute the below PnP script :

    ----------------------------------------------------------

                  

    $SiteUrl="https://***.sharepoint.com/sites/site1"
    $LocalPath="C:\temp\"
    $PageName="Template.aspx"


    $Username = "*****@*****.onmicrosoft.com" 
    $Password = "Pass@word321" 
    $siteURL = "https://*****.sharepoint.com/sites/site1" 
    $listName = "ROCESS1"


    $Folder="SitePages"
    $PageUrl=$Folder+"/Templates/"+$PageName
    #region Credentials 
    [SecureString]$SecurePass = ConvertTo-SecureString $Password -AsPlainText -Force 
    [System.Management.Automation.PSCredential]$PSCredentials = New-Object System.Management.Automation.PSCredential($Username, $SecurePass) 
    #endregion Credentials


    #Creating SharePoint Modern Pages by taking reference of Page Template

    Connect-SPOService -Url https://****-admin.sharepoint.com/ -Credential $PSCredentials
    Connect-PnPOnline -Url $siteURL -Credentials $PSCredentials
    Set-SPOSite -Identity $SiteUrl -DenyAddAndCustomizePages $false
    Get-PnPFile -Url $PageUrl -Path $LocalPath -FileName $PageName -AsFile -Force
    $listitems = Get-PnPListItem -List $listName
    foreach($listitem in $listitems){
     $pageNameBanner=$listitem["HexId"]+".aspx"
      $pageTitle= $listitem["ShortName"]
    $spfile=Add-PnPFile -Path $LocalPath$PageName -Folder $Folder -NewFileName $pageNameBanner
    Set-PnPClientSidePage -Identity $pageNameBanner -Title $pageTitle
    Set-PnPClientSidePage -Identity $pageNameBanner -Publish
    }


    #Adding Navigation node by taking pages names from "SitePages Library"

    Connect-PnPOnline -Url $siteURL -Credentials $PSCredentials
    $pages = Get-PnPListItem -List sitepages
    Add-PnPNavigationNode -Title "MegaMenu" -Url $SiteUrl -Location "QuickLaunch"
      foreach($page in $pages) {
          $ParentID = Get-PnPNavigationNode -Location QuickLaunch | Where {$_.Title -eq "MegaMenu"}  | Select -ExpandProperty ID
          Add-PnPNavigationNode -Title  $page["Title"] -Url  $page["FileRef"] -Location "QuickLaunch"  -Parent $ParentID

          }

    --------------------------------------------------------

    I got the below error:

    ---------------------------------------------------------------------

    format-default : The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
        + CategoryInfo          : NotSpecified: (:) [format-default], CollectionNotInitializedException
        + FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException,Microsoft.PowerShell.Commands.FormatDefaultCommand

    -------------------------------------------------------------------------

    Monday, September 30, 2019 9:36 AM
  • Hi,

    Check the PowerShell script below.

    $URL='https://tenant.sharepoint.com/sites/team'
    Connect-PnPOnline –Url $URL –Credentials (Get-Credential)
    $pages = Get-PnPListItem -List SitePages
    Add-PnPNavigationNode -Title "MegaMenu" -Url $SiteUrl -Location "QuickLaunch"
    foreach($page in $pages) {
        $ParentID = Get-PnPNavigationNode -Location QuickLaunch | Where {$_.Title -eq "MegaMenu"}  | Select -ExpandProperty ID
    	if($page["Title"]){
    		Add-PnPNavigationNode -Title $page["Title"] -Url  $page["FileRef"] -Location "QuickLaunch" -Parent $ParentID
    	}   
    }

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, October 1, 2019 8:45 AM
    Moderator