PnP Provisioning Engine template support for publishing pages ?

Copper Contributor

Is there any news on the support for publishing pages by the pnp provisioning engine.

if this functionality is not for the near future, any suggestions on how best to complement the provisioning (the provisioning is done using the powershell cmdlets)

 

Thanks

17 Replies

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?

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.

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. 

 

 

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.

 

hi when getting the provisioning the template did you use -IncludeNativePublishingFiles AND -PersistPublishingFiles

 

https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/GetPnPProvisioningTemplate.md

Sorry for the long wait

 

Yes I did use those 2 switchparameters. The pages are not persisted in the xml

(what it does do is persist the _catalog/master..... files in a separate directory.)

Is there a way to get web parts in zones on the pages as well?  I didn't think this was supported yet.

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>

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" %>

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>

 

 

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!

 

 

Hmmm...now how to handle upgrade scenarios where we want to redeploy the page...getting the old "duplicate web parts deployed issue"...

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...

Yeah, I was just reading up on the pnp:Providers and pnp:Extensions stuff as I was thinking that'd be the way to handle it.  Love to see your stuff as a starting point.  If not comfortable sharing here, let me know and we can look for other ways to communicate/collaborate.

 

Thanks!

Here you have it... Hope there's something usefull in it!

Beauty!  and +1 for use of "Paginas" 😉  Fond memories of that folder tripping us up on an old public MUI project from 2009 timeframe.

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