[英]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: 我们找到了一种不理想的解决方法,但可以起作用:
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,您需要:
https://<yourfarmsite>/catalogs/solutions/forms/allitems.aspx
导航到解决方案库: https://<yourfarmsite>/catalogs/solutions/forms/allitems.aspx
Solutions
Menu 单击Solutions
菜单 Upload Solution
点击Upload Solution
OK
浏览到您的自定义.wsp文件,然后单击“ OK
Activate
选择Web部件,然后单击Activate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.