【问题标题】:Sharepoint 2010 publishing site custom page layout webpart zoneSharepoint 2010 发布站点自定义页面布局 webpart 区域
【发布时间】:2011-05-24 10:25:54
【问题描述】:

我正在开发一个具有自定义页面布局的共享点发布网站。我想将一个 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 部件在创建页面后不存在。我在这里遗漏了什么吗?

【问题讨论】:

    标签: sharepoint sharepoint-2010


    【解决方案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>
    

    这会部署您的布局并使其可用于新的发布页面。现在,要在新页面中实例化 Web 部件,您可以使用 Web 部件定义修改 &lt;File&gt; 元素。例如,我可以像这样定义要在 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>
    

    这应该比创建一个全新的网站定义更实用。希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      如果您使用 SharePoint 功能部署这些页面布局并多次激活和停用该功能,则 Web 部件将出现在页面上的次数与您重新激活该功能的次数相同。似乎 SharePoint 没有直接的方法将 Web 部件的一个实例放在页面上

      【讨论】:

      • +1 - 我现在正在尝试解决这个问题。我想合乎逻辑的答案是实现一个功能事件接收器来处理这个问题(有关于已经解释如何做到这一点的资源)。还有一个完全不同的选择:code.msdn.microsoft.com/Adding-default-web-parts-ab7aec72
      【解决方案3】:

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

      【讨论】:

      • 你能给我举个例子吗?我不是很关注。此外,我有 5 种不同的页面布局,它们具有不同的 Web 部件组合,应该是可编辑的。
      • 谢谢,但这对我很有帮助。用户将如何删除该 Web 部件或更改其属性?
      • 具有最低贡献者访问权限的用户可以通过在浏览器中编辑页面来删除 Web 部件。也可以用同样的方式修改属性
      • ONET 对这个要求太过分了。
      猜你喜欢
      • 2012-08-23
      • 2011-09-21
      • 1970-01-01
      • 2012-04-12
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-17
      相关资源
      最近更新 更多