Pnp-sites-core: provision page layout + associated content type, publishing page instance

Created on 31 Jan 2017  Â·  5Comments  Â·  Source: pnp/PnP-Sites-Core

_From @dorin2006 on December 23, 2016 13:22_

People please help!!! Great tool, but...

  1. how to provision publishing page instance in pages library ?

Or this is not supported yet ?

thanks in advance!!!

p.s. I've managed to provision custom publishing page layout and associated content type ( not a publishing page instance yet ) as follows:





_Copied from original issue: SharePoint/PnP-Provisioning-Schema#158_

Most helpful comment

Hi @jansenbe and @VesaJuvonen

I am using the v2.13.1703 of SharePointPnPCoreOnline and it looks like Publishing Layouts and Pages are both being created without any problem with using the <pnp:File> element. My schema looks like this:

The pagelayout:

<pnp:File Src="PageLayouts\My.Custom.PageLayout.aspx" Folder="{masterpagecatalog}" Overwrite="true" Level="Published">
  <pnp:Properties>
    <pnp:Property Key="Title" Value="My Custom Page Layout" />
    <pnp:Property Key="MasterPageDescription" Value="My Custom Page Layout" />
    <pnp:Property Key="ContentType" Value="Page Layout" />
    <pnp:Property Key="UIVersion" Value="['15']" />
    <pnp:Property Key="PublishingAssociatedContentType" Value=";#Welcome Page;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4;#"/>
    <pnp:Property Key="PublishingPreviewImage" Value="{masterpagecatalog}/en-US/Preview%20Images/BlankWebPartPage.png, {masterpagecatalog}/en-US/Preview%20Images/BlankWebPartPage.png" />
  </pnp:Properties>
</pnp:File>

And then the page:

<pnp:File Src="PublishingPages\Home.aspx" Folder="{site}/Pages" Overwrite="true" Level="Published">
  <pnp:Properties>
    <pnp:Property Key="ContentTypeId" Value="{contenttypeid:Welcome Page}" />
    <pnp:Property Key="Title" Value="My Page Instance" />
    <pnp:Property Key="PublishingPageLayout" Value="{masterpagecatalog}/My.Custom.PageLayout.aspx, My Custom Page Layout" />
    <pnp:Property Key="PublishingPageContent" Value="Welcome" />
  </pnp:Properties>
  <pnp:WebParts>
    <pnp:WebPart Title="Content" Zone="wpz_Left" Order="0">
      <pnp:Contents>
        <WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
          <Title>My Title</Title>
          <FrameType>None</FrameType>
          <Assembly>Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
          <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
        </WebPart>
      </pnp:Contents>
    </pnp:WebPart>
  </pnp:WebParts>
</pnp:File>

Has this been included recently in the Provisioning engine?

All 5 comments

Hi @dorin2006,
since this is more around the PnP-Sites-Core engine, will relocate this to PnP-sites-Core repository for further processing.

Hi @dorin2006,

The engine does not natively support creating publishing pages, but community created a PnP provisioning extension that can do this for you. See https://github.com/SharePoint/PnP/blob/master/Samples/Provisioning.Extensibility/README.md.

Hope this will help you solve your problem. Will close the issue now.

Hi @jansenbe and @VesaJuvonen

I am using the v2.13.1703 of SharePointPnPCoreOnline and it looks like Publishing Layouts and Pages are both being created without any problem with using the <pnp:File> element. My schema looks like this:

The pagelayout:

<pnp:File Src="PageLayouts\My.Custom.PageLayout.aspx" Folder="{masterpagecatalog}" Overwrite="true" Level="Published">
  <pnp:Properties>
    <pnp:Property Key="Title" Value="My Custom Page Layout" />
    <pnp:Property Key="MasterPageDescription" Value="My Custom Page Layout" />
    <pnp:Property Key="ContentType" Value="Page Layout" />
    <pnp:Property Key="UIVersion" Value="['15']" />
    <pnp:Property Key="PublishingAssociatedContentType" Value=";#Welcome Page;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4;#"/>
    <pnp:Property Key="PublishingPreviewImage" Value="{masterpagecatalog}/en-US/Preview%20Images/BlankWebPartPage.png, {masterpagecatalog}/en-US/Preview%20Images/BlankWebPartPage.png" />
  </pnp:Properties>
</pnp:File>

And then the page:

<pnp:File Src="PublishingPages\Home.aspx" Folder="{site}/Pages" Overwrite="true" Level="Published">
  <pnp:Properties>
    <pnp:Property Key="ContentTypeId" Value="{contenttypeid:Welcome Page}" />
    <pnp:Property Key="Title" Value="My Page Instance" />
    <pnp:Property Key="PublishingPageLayout" Value="{masterpagecatalog}/My.Custom.PageLayout.aspx, My Custom Page Layout" />
    <pnp:Property Key="PublishingPageContent" Value="Welcome" />
  </pnp:Properties>
  <pnp:WebParts>
    <pnp:WebPart Title="Content" Zone="wpz_Left" Order="0">
      <pnp:Contents>
        <WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
          <Title>My Title</Title>
          <FrameType>None</FrameType>
          <Assembly>Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
          <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
        </WebPart>
      </pnp:Contents>
    </pnp:WebPart>
  </pnp:WebParts>
</pnp:File>

Has this been included recently in the Provisioning engine?

I have been trying to add a custom page layout and web part to my publishing site template for days! Thank you!

Hi @vman... I know it's over a year later I have been trying to provision a page with a web part with a very similar template using the schema from a similar time (5/2017). I am just trying to get it working with the standard default.aspx file that gets created with every new publishing site. I have been able to provision new pages fine and even write some content via PublishingPageContent property, but if i ever try to add any web parts I get errors. I’ve tried tweaking stuff with this template and using other variations of templates that I have found in the PnP repos but nothing seems to work. My template is below which I keeps giving me an error that says "There are multiple root elements" which I don't understand because this is valid XML. If I remove the block from this template, everything works fine.

<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2017/05/ProvisioningSchema">
  <pnp:Preferences Generator="OfficeDevPnP.Core, Version=2.19.1710.2, Culture=neutral, PublicKeyToken=null" />
  <pnp:Templates ID="CONTAINER-EMPTY-PUBLISHING">
    <pnp:ProvisioningTemplate ID="EMPTY-PUBLISHING" Version="1" ImagePreviewUrl="" BaseSiteTemplate="BLANKINTERNETCONTAINER#0" Scope="RootSite">

      <pnp:Files>
        <pnp:File Src="Pages\test.aspx" Folder="{site}/Pages" Overwrite="true" Level="Published">
          <pnp:Properties>
            <pnp:Property Key="ContentTypeId" Value="{contenttypeid:Welcome Page}" />
            <pnp:Property Key="Title" Value="Home" />
            <pnp:Property Key="PublishingPageLayout" Value="{masterpagecatalog}/BlankWebPartPage.aspx, Blank Web Part page" />
            <pnp:Property Key="PublishingPageContent" Value="&lt;p&gt;​​&lt;br&gt;This site was provisioned using the site provisioning form, this is an example of content inserted from the template​&lt;br&gt;​&lt;br&gt;&lt;/p&gt;" />
            <pnp:Property Key="BSN" Value="Microsoft.SharePoint.Client.FieldLookupValue" />
            <pnp:Property Key="_ListSchemaVersion" Value="47" />
            <pnp:Property Key="_Dirty" Value="0" />
            <pnp:Property Key="_Parsable" Value="1" />
            <pnp:Property Key="_VirusStatus" Value="0" />
            <pnp:Property Key="_VirusVendorID" Value="2275" />
          </pnp:Properties>
          <pnp:WebParts>
            <pnp:WebPart Title="Content" Zone="TopLeftRow" Order="0">
              <pnp:Contents>
                <WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
                    <Title>My Title</Title>
                    <FrameType>None</FrameType>
                    <Assembly>Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
                    <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
                </WebPart>
              </pnp:Contents>
            </pnp:WebPart>
          </pnp:WebParts>           
        </pnp:File>
      </pnp:Files>
    </pnp:ProvisioningTemplate>
  </pnp:Templates>
</pnp:Provisioning>

Do you have any ideas where I might be going wrong or if you still have it around provide the template that has worked for you? Thanks

Was this page helpful?
0 / 5 - 0 ratings