in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Ton Stegeman [MVP] weblog

I have moved my blog to http://www.tonstegeman.com/blog. If you have a blogpost at sharepointblogs that does not display all the content on the right hand side, please go to the new blog. It has all the posts that are on this blog as well. I you have any feedback, please send me a message through the contact form.

Associating the default page in a SharePoint 2007 publishing site with a custom content type and a custom page layout

In the MOSS 2007 intranets we build for our customers, we try to encourage them to use custom content types to manage the documents and publishing pages. In these projects we always create new page layouts, new content types and associate the page layouts with the new page layouts. The page layout contains the desired layout of the pages and the usercontrols that make it easier for users to edit the metadata while creating content.

For some reason we had never done this for the default page in a publishing site, which we had to do in one of our current projects. The issue here was that you need to set the content type and the page layout for the default.aspx in the site definition (onet.xml). At that stage our custom content type is not yet associated with the pages library, because that still is the out of the box Pages library. Once again SharePoint features are the solution here. More specific the “ContentTypeBinding” that is part of the “Elements” element helps here. In this post I will describe how I have set this up.

  • Create a site column called “Region” (this is just custom metadata to show the concept; it is a choice field)
  • Create a new content type called “MyArticleContentType”. It inherits from “Article Page” and has the extra Region site column.
  • Create a new Page Layout called “MyArticleLeft.aspx”. In my demo it is a copy of ArticleLeft. aspx and it has the extra user control for the Region field. I have added this control to the placeholder called “PlaceHolderMain” and added the control just between the ArticleStartDate and the ArticleByLine fields.

                      <SharePointWebControls:DropDownChoiceField 
                            FieldName="Region" 
                            runat="server" 
                            id="regionfield"
                      </SharePointWebControls:DropDownChoiceField>

  • Associate the page layout with the content type. Navigate to the Master page gallery in SharePoint find your page layout and select “Edit Properties” from the context menu. In the Associated Content Type section, select your custom content type, in my case “MyArticleContentType”.
    Pages1
  • Publish and approve your page layout.
  • Create a new feature (I called it “PagesContentTypeAssociation”). The feature.xml is just a reference to an elements manifest file:
  • <?xml version="1.0" encoding="utf-8" ?>
      <Feature  Id="9FAA95C2-E455-4a74-B9D5-C3C81DE8824A"
              Title="Association of content types for Pages Libraries"
              Scope="Web"
              Description="This feature associates content types to existing SharePoint lists."
              Version="1.0.0.0"
              xmlns="http://schemas.microsoft.com/sharepoint/">
      <ElementManifests>
        <ElementManifest Location="elements.xml"/>
      </ElementManifests>
    </Feature>
  • Create the elements manifest. In the Elements element, you need to add an ContentTypeBinding like in the example below:
    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <ContentTypeBinding 
        ContentTypeId="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D0000951B99779D25428408CD40276C0358" 
        ListUrl="Pages" />
    </Elements>
    The ContentTypeId referenced here is the ID of your custom content type. Because I created the content type manually by using the SharePoint user interface, I have to lookup the ID in SharePoint. You can find it by navigating to the properties of your content type and copying the id from the address bar of your browser:
    Pages2
  • Install the feature on your SharePoint farm
  • Create a new site definition. I just copied the “PUBLISHING” folder in the SiteTemplates folder and created a new registration for my new site definition by creating a new xml file called “webtempmycustomsite.xml” in the folder 12HIVE\TEMPLATE1033\XML.
  • Activate our new feature in the onet.xml of the new site definition. It has to be in WebFeatures, because the feature has the Web scope (as we want to activate is for each subsite)

  •     <WebFeatures>
          <!-- Activate the feature to associate the content type to the Pages library -->
          <Feature ID="9FAA95C2-E455-4a74-B9D5-C3C81DE8824A">
          </Feature>
         </WebFeatures>

  • Change the options for the default.aspx in onet.xml. Set both the ContentType and the PublishingPageLayout properties of the File “default.aspx”:
  •     <Module Name="Home" Url="$Resources:cmscore,List_Pages_UrlName;" Path="">
          <File Url="default.aspx" Type="GhostableInLibrary" Level="Draft" >
            <Property Name="Title" Value="My Welcome Page" />
            <Property Name="PublishingPageLayout" 
                      Value="~SiteCollection/_catalogs/masterpage/MyArticleLeft.aspx" />
            <Property Name="ContentType" Value="MyArticlePage" />
          </File>
        </Module>

  • IISRESET to activate the registration of the new site definition
  • Test your new site definition.
    After creating a new site and putting the default page in edit mode, you will see that you page is based on the correct page layout.
    Pages3
    In the properties of the page you can see that it is now based on the new custom content type.

 

Comments

No Comments

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts