开发者

Sharepoint 2010 publishing site custom page layout webpart zone

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 开发者_C百科page is created. Am I missing something here?


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.


If you deploy these page layouts using the SharePoint feature and activate and deactivate feature several times the web part will appear on the page as many times as you re-activate the feature. It seems that SharePoint does not have straightforward way to put just one instance of the web part on the page


I would suggest use Onet.xml provided with your site definition to add a webpart to page. Page layout is for providing a Page Layout not for personalizing it for your custom site. So please use Onet.xml for this purpose

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜