Search This Blog

Tuesday, February 21, 2012

Create Pages using Custom Page Layout & Deploy them in Pages library

In my last post I described how to create custom page layouts.
Now using those page layouts, we need to create Pages and deploy them in pages library of the publishing site.
Follow the below mentioned steps in order to achieve the above.
  • Create a new module within the solution (say MyPages)
  • Delete the sample.txt file.
  • Add a text file within the module and rename it to Home.aspx

  • Add the required directives in Home.aspx page and add web part zones within the page. You can download Home.aspx page here.
  • Open the Elements.xml file and make changes accordingly as shown below
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="MyPages" Url="Pages">
    <File Path="MyPages\Home.aspx" Url="Home.aspx" Type="GhostableInLibrary" NavBarHome="True">
      <Property Name="Title" Value="Home" />
      <Property Name="PublishingPageImage" Value="&lt;img alt=&quot;Welcome&quot; src=&quot;~SiteCollection/PublishingImages/HomeBanner.jpg&quot; &gt;"></Property>
      <Property Name="PublishingPageLayout"
                   Value="~SiteCollection/_catalogs/masterpage/HomePage.aspx, Home Page" />
      <Property Name="ContentType" Value="MyCustomContentType" />    
    </File>
</Module>
</Elements>
  •  Deploy the solution and you should be able to see Home.aspx page created in the pages library using the custom page layout created.
  • We have specified that this page should be deployed to Pages library in our Elements.xml file of this module. (URL="Pages")

No comments:

Post a Comment