Forum Discussion
PnP Provisioning Engine template support for publishing pages ?
You can provision Publishing Pages using PnP, see an example below:
<pnp:File src="mypublishingpage.aspx" Folder="{site}/Pages" Overwrite="true"> <pnp:Properties> <pnp:Property Key="ContentTypeId" Value="{contenttypeid:MyPageContentType}" /> <pnp:Property Key="Title" Value="My Publishing Page" /> <pnp:Property Key="PublishingPageLayout" Value="{sitecollection}/_catalogs/masterpage/MyPageLayout.aspx, My Page Layout" /> </pnp:Properties>
</pnp:File>
In this example a Publishing page with the filename mypublishingpage.aspx is provisioned to the pages library using the specified Content Type and Page Layout.
Are there any specific challenges you face when provisioning Publishing Pages?
Can you point to a sample set of files (template.xml and any others needed) to deploy a publishing page? I am trying to do it using the <pnp:File>, but I get an ArgumentNullException related to the "stream" parameter of the "Microsoft.SharePoint.Client.FileFolderExtensions.UploadFile" using an XML structure very similar to that which you provide (btw - typo in the "src" attribute - should be "Src").
Do I need a local file matching the "Src" attribute for upload. Perhaps with the TemplateRedirect content in it?
<%@ Page Inherits="Microsoft.SharePoint.Publishing.TemplateRedirectionPage, Microsoft.SharePoint.Publishing,Version=15.0.0.0,Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Reference VirtualPath="~TemplatePageUrl" %> <%@ Reference VirtualPath="~masterurl/custom.master" %>
- paulpaschaFeb 22, 2017Bronze Contributor
Yes, you need a local file for what you specified in the src attribute. So in my code sample below mypublishingpage.aspx should be a local file located at the location you specified in your TemplateProvider (connectionstring / container). If you use PowerShell to apply your template the file should be located in location within or relative to the folder from which your PowerShell is executed
The contents of the file, in case where a PublishingPageLayout should indeed be the TemplateRedirectionPage markup you mentioned.
<pnp:File src="mypublishingpage.aspx" Folder="{site}/Pages" Overwrite="true"> <pnp:Properties> <pnp:Property Key="ContentTypeId" Value="{contenttypeid:MyPageContentType}" /> <pnp:Property Key="Title" Value="My Publishing Page" /> <pnp:Property Key="PublishingPageLayout" Value="{sitecollection}/_catalogs/masterpage/MyPageLayout.aspx, My Page Layout" /> </pnp:Properties> <pnp:WebParts> <pnp:WebPart Order="0" Title="Your WebPart Title" Zone="Center"> <pnp:Contents> <!-- your exported WebPart XML --> </pnp:Contents> </pnp:WebPart> </pnp:WebParts> </pnp:File>
- BrianPMcCullough00Feb 22, 2017Copper Contributor
Hmmm...now how to handle upgrade scenarios where we want to redeploy the page...getting the old "duplicate web parts deployed issue"...
- paulpaschaFeb 22, 2017Bronze Contributor
We've implemented a custom Provider / Extensibility Handler to handle some upgrade scenarios (e.g. overwriting a previously deployed WebPart, removing WebParts not defined in your template). I can share the raw code with you if you like...
- Tim BowdenSep 13, 2017Copper Contributor
Sorry to revisit this, but I am trying to do exactly this in PowerShell and keep getting an invalid file template.
The error occurs when I try to add the webparts tag after the properties tag.
Thanks
Tim
- BrianPMcCullough00Feb 22, 2017Copper Contributor
FYI...I put a file with the name matching the Src in the same directory as the template XML file and filled it with the TemplateRedirect stuff. That seems to do the trick! I even pushed with a ScriptEditor web part also!