Jan 19, 2012

Creating a Content Type for Custom PageLayouts

Even when you don't use any custom fields on your PageLayouts, and necessary if you do, it is worth its while to create a custom content type (or several, if you need to apply different fields to different PageLayouts) for your PageLayouts for several reasons:

  • custom content type enables grouping the PageLayouts in meaningful groups instead of the Custom group in the PageLayout menu
  • also, for content rollup with CQWP, with custom content type, it is possible to list only the pages that are of the specific content type
  • when using custom fields as well, it is possible to filter the content rollup by the custom field info

Creating the basic Content Type is a quick task. Add a new item to your SharePoint project, of the type Content Type:


Select then "Page Layout" as the base Content Type to inherit from, or one of your existing Content Types:


Edit the Elements.xml; change the Name, Group and Description to your liking.


If you want to create some custom fields for your content types, add the fields to the Elements.xml as Field-elements:


Generate GUIDs for the IDs of the fields.

Then add the field references to the Content Type FieldRefs. After that the Elements.xml should look something like this:


Now, to use this with your PageLayouts, first, set the Content Type of the PageLayout to your custom Content Type in the Elements.xml containing the PageLayout elements by setting the Content Type value and adding a PublishingAssociatedContentType-property with the ContentType ID to the file(s):


If you want to make it easier for the users to fill in the fields, add them to the PageLayout EditPanel:


FieldName gets the GUID ID you generated for the field. 

And maybe some information needs to be visible too, add those fields to the page html as well:


In edit mode, the page looks now like this: 


The Content owner is visible on page (and a bit stylized here):


(Page content from http://slipsum.com, my favorite Lorem Ipsum.)

No comments: