Question

I am trying to provision a publishing page to the pages library using visual studio. I am using a module and my code looks like below:

 <File Path="CustomPageLayout.aspx" Url="ContactDetails.aspx" ReplaceContent="TRUE"
      Type="GhostableInLibrary">
  <Property Name="Title" Value="Contact Details" />
  <Property Name="MasterPageDescription" Value="" />
  <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/CustomPageLayout.aspx , /_catalogs/masterpage/CustomPageLayout.aspx" />
  <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
</File>

The page layout is not applied when the page is created. How do I solve this.

I can set the page layout on other pages, so it's working fine, but am having problems on provisioning new pages.

EDIT:

I now updated my code to this:

 <Module Name="Pages" Url="Pages" SetupPath="FEATURES\Website_Website\Website">
        <File Path="CustomPageLayout.aspx" Url="ContactDetails.aspx" ReplaceContent="TRUE" Type="GhostableInLibrary">
            <Property Name="Title" Value="test page" />
            <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/CustomPageLayout.aspx, My Layout" />
            <Property Name="ContentType" Value="Welcome Page" />

       </File>
  </Module>

Since I am deploying my page layout through another feature, so I am using SetupPath. Any idea where I might be wrong here?

Était-ce utile?

La solution

You need to update your .xml file as below

<File Path="LayoutPage.aspx" Url="InnerPage.aspx"  Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" ReplaceContent="True">
<Property Name="Title" Value="Layout Page"></Property>
<Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
<Property Name="PublishingAssociatedContentType" Value=";#Layout Page;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D400181D9406C08A47248593C844813E920D;#" />
<Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
</File>

Hope this will help you!

Autres conseils

You provided wrong ContentType value, contenttype_pagelayout_name references page layout content type and usually used to create new page layouts.
Since you are creating a new publishing page, you need to put the value of PublishingAssociatedContentType from corresponding page layout. In your case you need to know which content type is associated with CustomPageLayout.aspx.

For example for out of the box content type, it will be

<Property Name="ContentType" Value="Welcome Page" />

Or via Id:

<Property Name="ContentTypeId" Value="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4" />   

Also, PublishingPageLayout it's try to provide page layout's name:

<Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/CustomPageLayout.aspx, <Page layout name here>" />   

It's a good practice to use SharePoint hive to know the right structure.
For example here is the page layout definition for one of the SharePoint site definitions:

<Module Name="MPGPopulation" Url="_catalogs/masterpage" Path="" RootWebOnly="TRUE">
    <File Url="DefaultLayout.aspx" Type="GhostableInLibrary" >
        <Property Name="Title" Value="$Resources:spscore,DefaultLayoutTitle;" />
        <Property Name="MasterPageDescription" Value="$Resources:spscore,DefaultLayoutDescription;" />
        <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
        <Property Name="PublishingAssociatedContentType" Value=";#$Resources:cmscore,contenttype_welcomepage_name;;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4;#" />
        <Property Name="PublishingHidden" Value="TRUE" />
    </File>
    ......  

And corresponding publishing page based on this page layout:

<File Url="Default.aspx" Type="GhostableInLibrary">
    <Property Name="Title" Value="$Resources:spscore,HomeLandingPage_Title;" />
    <Property Name="ContentType" Value="$Resources:cmscore,contenttype_welcomepage_name;" /> <--- Welcome Page
    <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/defaultlayout.aspx, $Resources:spscore,DefaultLayoutTitle;" />
    <Property Name="PublishingPageImage" Value="&lt;img border=&quot;0&quot; src=&quot;~SiteCollection/PublishingImages/newsarticleimage.jpg&quot; vspace=&quot;0&quot; style=&quot;margin-top:8px&quot; alt=&quot;&quot;&gt;" />  

UPD
Based on your updated answer you need something similar to this one:

Page Layout:
<File Path="CustomPageLayout.aspx" Url="ContactDetails.aspx" ReplaceContent="TRUE" Type="GhostableInLibrary">
  <Property Name="Title" Value="Contact Details" />
  <Property Name="MasterPageDescription" Value="Contact Details page layout" />
  <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
  <Property Name="PublishingAssociatedContentType" Value=";#$Resources:cmscore,contenttype_welcomepage_name;;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4;#" />
</File>  
Publishing page based on custom page Layout:
 <Module Name="Pages" Url="Pages" SetupPath="FEATURES\Website_Website\Website">
        <File Path="CustomPageLayout.aspx" Url="ContactDetails.aspx" ReplaceContent="TRUE" Type="GhostableInLibrary">
            <Property Name="Title" Value="test page" />
            <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/ContactDetails.aspx, Contact Details" />
            <Property Name="ContentType" Value="Welcome Page" />
       </File>
  </Module>
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top