简体   繁体   English

Sharepoint 2010发布网站自定义页面布局webpart区域

[英]Sharepoint 2010 publishing site custom page layout webpart zone

I'm working on a sharepoint publishing site that has custom page layouts. 我正在开发一个具有自定义页面布局的sharepoint发布网站。 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. 我想将Web部件区域添加到其中一个自定义布局中,该布局显示默认Web部件,然后用户可以删除或更改创建页面时的属性。

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. Web部件区域可用于添加Web部件,但在创建页面后,我的默认Web部件不存在。 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. 这样,您可以将页面布局部署到任何SharePoint发布网站。 If you are using VS 2010, start with a SharePoint Module project. 如果您使用的是VS 2010,请从SharePoint模块项目开始。 Add your layout aspx file to the project. 将布局aspx文件添加到项目中。 Modify the elements.xml file to resemble this: 修改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>

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. 现在,要在新页面中实例化webpart,可以使用webpart定义修改<File>元素。 For example, I could define a content editor webpart to be created on new pages in Zone1 like this: 例如,我可以在Zone1中的新页面上定义要创建的内容编辑器webpart,如下所示:

<?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. 如果使用SharePoint功能部署这些页面布局并多次激活和取消激活功能,则在重新激活该功能时,Web部件将在页面上显示多次。 It seems that SharePoint does not have straightforward way to put just one instance of the web part on the page 似乎SharePoint没有简单的方法只在页面上放置一个Web部件实例

I would suggest use Onet.xml provided with your site definition to add a webpart to page. 我建议使用随网站定义提供的Onet.xml将webpart添加到页面。 Page layout is for providing a Page Layout not for personalizing it for your custom site. 页面布局用于提供页面布局,而不是为自定义网站个性化。 So please use Onet.xml for this purpose 所以请为此目的使用Onet.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM