首页 文章

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

提问于
浏览
2

我正在开发一个具有自定义页面布局的sharepoint发布网站 . 我想将Web部件区域添加到其中一个自定义布局中,该布局显示默认Web部件,然后用户可以删除或更改创建页面时的属性 .

我正在尝试这个:

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

Web部件区域可用于添加Web部件,但在创建页面后,我的默认Web部件不存在 . 我在这里错过了什么吗?

3 回答

  • 2

    我建议使用随网站定义提供的Onet.xml将webpart添加到页面 . 页面布局用于提供页面布局,而不是为自定义网站个性化 . 所以请为此目的使用Onet.xml

  • 1

    您还可以将页面布局部署为单个功能,而不是创建整个网站定义 . 这样,您可以将页面布局部署到任何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> 元素 . 例如,我可以在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>
    

    这应该比创建一个全新的网站定义更实用 . 希望这可以帮助 .

  • 7

    如果使用SharePoint功能部署这些页面布局并多次激活和取消激活功能,则在重新激活该功能时,Web部件将在页面上显示多次 . 似乎SharePoint没有简单的方法只在页面上放置一个Web部件实例

相关问题