Skip to main content

Cloud

Create a custom content type that inherits from PageLayout using a SharePoint feature

Problem

You want to create your own content type that inherits from PageLayout. This will allow you to define your own meta-data for pages that are created in your sites.

Assumptions

This post assumes that you are using Visual Studio to develop and deploy your SharePoint feature.

Solution

1.) Locate the ID of the parent content type from which you want to inherit your type. In this case, we are inheriting from PageLayout; the definition, of which, is located in FEATURES/PublishingResources/PublishingContentTypes.xml

<ContentType ID="0x01010007FF3E057FA8AB4AA42FCB67B453FFC100E214EEE741181F4E9F7ACC43278EE811"
Name="$Resources:cmscore,contenttype_pagelayout_name;"
Description="$Resources:cmscore,contenttype_pagelayout_description;"
Group="$Resources:cmscore,group_publishingcontenttypes;" Sealed="FALSE" Version="0">
<FieldRefs>
</FieldRefs>
<DocumentTemplate TargetName="/_layouts/NewPageLayout.aspx" />
<ContentType>

2.) Create your own ID using the ID of the parent content type. Append a ’00’ to the end of the parent ID, then in the Visual Studio Tools menu select Create Guid. Strip the brackets and dashes from the generated guid and append the result to the end of the ID. This is your content type’s ID.

PageLayoutID: 0x01010007FF3E057FA8AB4AA42FCB67B453FFC100E214EEE741181F4E9F7ACC43278EE811
Document: 00
Guid: 48ECF65594C344be9CCA1DD50186B53E

3.) In your Elements.xml file, add a complete definition for your content type using the ID above.

<?xml version="1.0" encoding="utf-8" ?>

<!– _lcid="1033" _version="12.0.4518" _dal="1" –>

<!– _LocalBinding –>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<ContentType ID="0x01010007FF3E057FA8AB4AA42FCB67B453FFC100E214EEE741181F4E9F7ACC43278EE8110048ECF65594C344be9CCA1DD50186B53E"

Name="MyPage"

Group="My Group"

Description="Content Type that inherits from PageLayout"

Version="0">

<FieldRefs>

</FieldRefs>

<DocumentTemplate TargetName="/_layouts/NewPageLayout.aspx" />

</ContentType>

</Elements>

Discussion

If you are going to add custom columns to the definition, using the FieldRefs tag, you can only include fields that have been defined as Site Columns. To accomplish this, you will need to create a separate feature that creates the columns, or manually create the columns in your site.

The FieldRefs tag is required to inherit the columns of the parent type.

The DocumentTemplate tag allows you to point this content type to a document that will act as the template for any documents created in a library with this content type.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Dave Scheele

More from this Author

Follow Us