2010-12-13 159 views
2

我正在处理具有自定义页面布局的SharePoint发布网站。我想向其中一个自定义布局添加一个Web部件区域,以呈现默认Web部件,然后用户可以删除或更改创建页面时的属性。Sharepoint 2010发布网站自定义页面布局webpart区域

我想这一点:

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

的Web部件区域是可添加的webpart,而是创建了一个页面后,我的默认Web部件不存在。我在这里错过了什么吗?

回答

1

我建议使用随网站定义提供的Onet.xml来添加一个webpart到页面。页面布局用于提供页面布局,而不是为您的自定义站点进行个性化设置。因此,请为此使用Onet.xml

+0

请您指点我一个示例吗?我不太喜欢。另外,我有5种不同的页面布局,它们会有不同的应该可编辑的Web部件组合。 – ScottE 2010-12-13 12:15:47

+0

http://msdn.microsoft.com/en-us/vcsharp/ff623012.aspx视频链接 – 2010-12-13 13:03:25

+0

谢谢,但这对我真的很有帮助。用户如何移除该Web部件或更改其属性? – ScottE 2010-12-13 13:39:04

7

您也可以将您的页面布局作为单个功能部署,而不是创建整个网站定义。这样,您可以将页面布局部署到任何SharePoint发布网站。如果您使用VS 2010,请从SharePoint模块项目开始。将您的布​​局aspx文件添加到项目中。修改elements.xml文件以类似于此:

<?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> 

这将部署您的布局并使其可用于新的发布页面。现在,为了让webpart在新页面中实例化,可以使用webpart定义修改<File>元素。例如,我可以定义一个内容编辑器web部件将在1区新页面创建这样的:

<?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> 

这应该是比创造一个全新的网站定义更加实用。希望这可以帮助。

2

如果您使用SharePoint功能部署这些页面布局,并多次激活和停用功能,则Web部件将在重新激活功能时出现在页面上多次。看起来SharePoint并没有简单的方法在页面上放置一个Web部件的实例

+1

+1 - 我正在试图解决这个问题。我想合乎逻辑的答案是实现一个功能事件接收器来处理这个问题(有些资源已经解释了如何做到这一点)。还有一个完全不同的选择:http://code.msdn.microsoft.com/Adding-default-web-parts-ab7aec72 – 2012-05-30 12:09:47

相关问题