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?>
  <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=<img alt="Welcome" src="~SiteCollection/PublishingImages/HomeBanner.jpg" >></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”)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s