SharePoint: Provision a Page Layout using a Feature

In a publishing environment, we undoubtedly create new page layouts based either on existing or custom page layout content types, examples of stock publishing page layout content types include;

  1. Article Page
  2. Welcome Page

When we create a new page layout and want to provision it into SharePoint as part of a greater solution you will want to package it up as part of a feature. This is done using a CAML Module element as shown.

Create a new element manifest file called pagelayouts.xml and reference it in your feature manifest file.

<?xml version="1.0" encoding="utf-8"?>
<Feature  Id="bf7f11b6-4ec1-44fc-9c0f-84ccc3e78637"
          Title="Page Layouts feature"
          Description="This feature provisions page layouts."
		<ElementManifest Location="pagelayouts.xml"/>
		<ElementFile Location="MyLocationPage.aspx"/>

In the pagelayouts.xml file insert the following CAML;

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="">
	<Module Name="PageLayoutsModule"
		<File Url="MyLocationPage.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE">
			<Property Name="Title" Value="My Location Page"></Property>
			<Property Name="MasterPageDescription" Value="A Location Page ."></Property>
			<Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;"></Property>
			<Property Name="PublishingPreviewImage" Value="/_layouts/images/FTS/preview/PreviewLayoutLocation.png"></Property>
			<Property Name="PublishingAssociatedContentType" Value=";#My Location;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39005AD7C37FF2B8AB4AAD81FBF15F35702C;#"></Property>

The Modue and File elements are pretty standard CAML. Remember that the masterpage gallery is actually a list and what we are doing is creating a new listitem in that list. So it should come as no surprise that the Property elements are used to populate the listitems columns. The Property elements are described below;

  1. Title – the value used for the Page Layouts title
  2. MasterPageDescription – a brief description of the page layouts
  3. ContentType – since this is a page layout we want to set the list items content type to be a “Page Layout”, use the resource strings rather than free text since they are localizable
  4. PublishingPreviewImage – the url to a custom or stock page layout preview image
  5. PublishingAssociatedContentType – this is the really important one and it associates the page layout with an underlying content type, the so called page layout content type

The format of the PublishingAssociatedContentType value is;

;#{Content Type Name};#{Content Type ID};#

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

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.