简体   繁体   English

将WebPart添加到发布页面布局

[英]Add a WebPart to a publishing page layout

I've been trying to figure out a way to add a web part onto a page layout. 我一直在尝试找到一种将Web部件添加到页面布局的方法。 Whenever I try to add a web part zone or web part via the menus in SharePoint Designer, nothing happens. 每当我尝试通过SharePoint Designer中的菜单添加Web部件区域或Web部件时,都不会发生任何事情。 The web part I selected is highlighted blue, but nothing happens. 我选择的Web部件突出显示为蓝色,但没有任何反应。

I have been trying to add the .webpart code on the .aspx page layout with zero luck. 我一直试图在运气为零的情况下在.aspx页面布局上添加.webpart代码。

<WebPartPages:WebPartZone>
    <ZoneTemplate>
        .webpart code in here! 
    </ZoneTemplate>
</WebPartPages:WebPartZone>

The above just shows the web part zone, and the ability to add a web part, but doesn't show my web part. 上面仅显示了Web部件区域,以及添加Web部件的功能,但未显示我的Web部件。

I've tried placing the code outside the Zone Template and the WebPartZone , but I typically just get everything between the property tags displaying as text. 我尝试将代码放置在Zone Template和WebPartZone ,但是通常我只是将所有属性标签之间的所有内容显示为文本。

You cannot add the codes to get your webpart embeded on a page , you have to open the page layout in a designer and drop the webpart on that specific area - there may not be anyother work around for this 您无法添加代码以将Webpart嵌入页面中,您必须在设计器中打开页面布局并将Webpart放到该特定区域上-对此可能没有其他解决方法

Regards Arjun 问候阿琼

SharePoint was not updated to support creating the snippet of code to add the WebPart to the Page Layout like it is possible with old fashioned WebParts. SharePoint未更新为支持创建代码段,以将WebPart添加到页面布局中,就像老式WebParts一样。

Even when inserted in the Page Layout .html file, it is stripped out when the corresponding .aspx file is generated. 即使插入到页面布局.html文件中,也将在生成相应的.aspx文件时将其删除。

We found a workaround which is far from ideal but works: 我们找到了一种不理想的解决方法,但可以起作用:

  • Edit your Page Layout as you would normally in HTML 像通常在HTML中一样编辑页面布局
  • Add a WebPart zone where you would like to see the WebPart 在要查看WebPart的地方添加一个WebPart区域
  • Save the HTML and let SharePoint generate the aspx file 保存HTML并让SharePoint生成aspx文件
  • Manually edit the aspx file -- don't use SharePoint Designer, as it will strip out what you added -- with a plain text editor and insert the code from the webpart definition (the XML file) 手动编辑aspx文件-不要使用SharePoint Designer,因为它将删除添加的内容-使用纯文本编辑器并从Webpart定义中插入代码(XML文件)
  • Save the aspx and when you create a page using the page layout, your SPFx webpart should be there 保存aspx,并在使用页面布局创建页面时,您的SPFx Webpart应该存在

Note that for the WebParts parameters, it is stored as a JSON structure encoded in HTML. 请注意,对于WebParts参数,它存储为以HTML编码的JSON结构。 To figure out how to setup default parameters in the inserted WebPart, insert it into a regular page manually and look at what has been generated in the aspx file. 若要弄清楚如何在插入的WebPart中设置默认参数,请将其手动插入到常规页面中,并查看在aspx文件中生成了什么。 Then find the long line that has the encoded JSON structure and copy it back to your edited aspx file. 然后找到具有已编码JSON结构的长行,然后将其复制回您已编辑的aspx文件中。

Finally, never edit/save your page layout HTML file since it ewill then simply override your changes. 最后,切勿编辑/保存页面布局HTML文件,因为它将简单地覆盖您的更改。 I would keep a copy of your edited aspx file just in case! 我会保留您编辑的aspx文件的副本,以防万一!

It sounds like you're trying to use a Visual Web Part with SharePoint Online, which you can't do. 听起来您正在尝试将Visual Web部件与SharePoint Online一起使用,但是您不能这样做。 Web parts for SharePoint Online need to be packaged as a part of a solution. SharePoint Online的Web部件需要打包为解决方案的一部分。

To deploy a solution to SharePoint Online you need to: 要将解决方案部署到SharePoint Online,您需要:

  1. Navigate to the solutions gallery: https://<yourfarmsite>/catalogs/solutions/forms/allitems.aspx 导航到解决方案库: https://<yourfarmsite>/catalogs/solutions/forms/allitems.aspx
  2. Providing that you are logged in with the correct account and have permissions, this will take you to the solution gallery, where you can upload and activate custom web parts for site. 假设您使用正确的帐户登录并具有权限,这将带您到解决方案库,在此您可以上载和激活网站的自定义Web部件。
  3. Click the Solutions Menu 单击Solutions菜单
  4. Click Upload Solution 点击Upload Solution
  5. Browse to your custom .wsp file and click OK 浏览到您的自定义.wsp文件,然后单击“ OK
  6. After the web part has been uploaded, you can activate it; Web部件上载后,可以激活它; select the web part and click Activate 选择Web部件,然后单击Activate
  7. Now that the custom web part is uploaded and activated in the Solution Gallery, you can edit the site page that you want to add it to and then add it as per a normal web part. 现在,自定义Web部件已在解决方案库中上载并激活,您可以编辑要将其添加到的网站页面,然后按照常规Web部件进行添加。

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

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