Sharepoint 2010 publishing site custom page layout webpart zone

sharepointsharepoint-2010

I'm working on a sharepoint publishing site that has custom page layouts. I'd like to add a web part zone to one of the custom layouts that present a default web part that the user can then remove or change the properties of when they create a page.

I'm trying this:

<WebPartPages:WebPartZone id="zone1" runat="server" title="Zone 1">
<ZoneTemplate>
<Something:LookingForLinks runat="server" id="wp_lookingForLinks"/>
</ZoneTemplate>
</WebPartPages:WebPartZone>

The web part zone is available for adding webparts, but my default web part is not present after a page is created. Am I missing something here?

Best Answer

You could also deploy your page layouts as an individual feature rather than creating a whole site definition. That way you could deploy your page layouts to any SharePoint publishing site. If you are using VS 2010, start with a SharePoint Module project. Add your layout aspx file to the project. Modify the elements.xml file to resemble this:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="Page Layouts" Url="_catalogs/masterpage" RootWebOnly="True">
    <File Path="Page Layouts\Layout1.aspx" Url="Layout1.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="True">
      <Property Name="Title" Value="My Layout 1" />
      <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
    </File>
   </Module>
</Elements>

This deploys your layout and makes it available as for new publishing pages. Now, to get a webpart to be instantiated in new pages, you modify the <File> element with the webpart definition. For example, I could define a content editor webpart to be created on new pages in Zone1 like this:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="Page Layouts" Url="_catalogs/masterpage" RootWebOnly="True">
    <File Path="Page Layouts\Layout1.aspx" Url="Layout1.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="True">
      <Property Name="Title" Value="My Layout 1" />
      <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
      <AllUsersWebPart WebPartZoneID="Zone1" WebPartOrder="1">
        <![CDATA[ 
               <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
                <Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
                <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
                <Title>Content Editor</Title>
                <FrameType>Default</FrameType>
                <FrameState>Normal</FrameState>
                <Description></Description>
                <Height />
                <Width />
                <AllowRemove>true</AllowRemove>
                <AllowZoneChange>true</AllowZoneChange>
                <AllowMinimize>true</AllowMinimize>
                <AllowConnect>true</AllowConnect>
                <AllowEdit>true</AllowEdit>
                <AllowHide>true</AllowHide>
                <IsVisible>true</IsVisible>
                <DetailLink />
                <HelpLink />
                <HelpMode>Modeless</HelpMode>
                <Dir>Default</Dir>
                <PartImageSmall />
                <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
                <PartImageLarge>/_layouts/images/homepage.gif</PartImageLarge>
                <IsIncludedFilter />
                <ExportControlledProperties>true</ExportControlledProperties>
                <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
                <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
                </Content>
                <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
                </WebPart>        
        ]]>
      </AllUsersWebPart>
    </File>
  </Module>
</Elements>

This should be more practical than creating a whole new site definition. Hope this helps.