SharePoint: Create a Publishing Page in a Site Definition using a Custom Page Layout

In a publishing environment we often create custom page layouts based on our own content types, and of course if we are also creating custom site definitions, we’ll probably want to create pages in the site defs which are based on our custom page laouts – how do we do this?

Again, it’s all done using a CAML module element as shown below;

<Module Name="PublishingHomePage" Url="$Resources:cmscore,List_Pages_UrlName;" Path="">
	<File Url="Default.aspx" Type="GhostableInLibrary">
		 <Property Name="Title" Value="Hom" />
		 <Property Name="ContentType" Value="My Location Page" />
		 <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/MyLocationPage.aspx, My Location Page Layout" />
		 <Property Name="PublishingPageContent" Value="Welcome to the Publishing Site" />

The Property elements are used to set the column values of the new listitem which is created in the Pages library for this page.

  1. Title – The page title, this is what is usually displayed at the top of the browser window
  2. ContentType – the listitems contentype (name), which should be the content type used as the basis of the page layout
  3. PublishingPageLayout – this is the important one, this tells SharePoint what page layout to associate with the listitem (page), it has a very specific format and a gotcha (see below)
  4. PublishingPageImage, PublishingPageContent etc – you can populate any other columns here.

The PublishingPageLayout property format is;

{the url of the page layout}, {the title value of the page layout}

The gotcha is in the use of the comma (,); either don’t use it and just specify the url of the page layout, or, if you do use it make sure you leave a space character after the comma.

The title value specified after the comma is displayed in the “Page Layout” column in the Pages library.

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

One thought on “SharePoint: Create a Publishing Page in a Site Definition using a Custom Page Layout

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.