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?
- BrianPMcCullough00Feb 22, 2017Copper Contributor
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"...
- 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!
- Danny FonckeFeb 16, 2017Copper Contributor
Thanks for the quick response Paul :)
I provision a site using the pnp get...template and apply...template powershell cmdlets.
I noticed that publishing pages are not included in the template.
Hence the first part of my question : is this coming in the near future.
Second part : If I have to do it myself, what is the best method taking into account that I want to 'copy' an existing page (in a source site) to a target site.If so advisable I can get... the template, add xml to it manually, and then use that extended template to provision the pages.
I will need to come up with the xml that provisions everything as is on the source page.Thanks again.
- paulpaschaFeb 16, 2017Bronze Contributor
Ah I see what you mean...
I don't know about planned support. Maybe VesaJuvonen can share some info on this....
We've done quite a few custom development projects in which defining our templates with Publishing Pages was largely a manual proces.
- Danny FonckeFeb 16, 2017Copper Contributor
It would already be nice to have a way to get the xml for a page (the pages) using the pnp engine :)
even if the engine is not capable of applying it to another site.
- BrianPMcCullough00Feb 22, 2017Copper Contributor
Is there a way to get web parts in zones on the pages as well? I didn't think this was supported yet.
- paulpaschaFeb 22, 2017Bronze Contributor
In my experience adding WebParts to Publishing Pages works just fine by including a definition like below in your pnp:File
<pnp:WebParts> <pnp:WebPart Order="0" Title="Your WebPart Title" Zone="Center"> <pnp:Contents> <!-- your exported WebPart XML --> </pnp:Contents> </pnp:WebPart> </pnp:WebParts>