0

I have created some SPFx webparts and am able to add it into a custom page layout by adding it into the webpartzone as below in the html, and through the use of design manager.

<!--SPM:<%@Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version = 16.0.0.0, Culture = neutral,  PublicKeyToken = 71e9bce111e9429c"%>-->
<!--MS:<WebPartPages:WebPartZone runat = "server" AllowPersonalization = "false" ID = "top_webpart" FrameType = "TitleBarOnly" Orientation = "Vertical" >-->
<!--MS:<ZoneTemplate >--> 
<!--ME:</ZoneTemplate >-->
<!--ME:</WebPartPages:WebPartZone >-->

However, instead of allowing authors to change the webpart, I will like to hardcode the webpart in the page layout so that it cannot be changed. I have read how to get a webpart snippet through https://docs.microsoft.com/en-us/sharepoint/dev/general-development/how-to-add-a-web-part-zone-snippet-in-sharepoint#inserting-a-web-part-zone-snippet but the snippet gallery (including Other Web Parts) does not include custom webpart in its list.

How can I get/come up with the snippet for the custom webpart?

Related: Is there any way to have a static custom made SPFx web-part in a page-layout template you have created in Design manager (Sharepoint Online)?

1 Answer 1

1

First add your web part to a classic page. Export it, and upload into the web part Gallery. It should now be available to design manager. Generate the snippet and the trick is to add the snippet to the page layout but outside of a webpart zone. When the webpart is not part of a zone it will prevent users from being able to edit it.

5
  • can you elaborate how i can export it and upload into the web part gallery? Do you mean to download the page as an aspx file?
    – Wee
    Jul 25, 2018 at 9:58
  • Open the page in edit mode. Select the web part and in its top corner you will see the menu to edit properties and at the bottom of that menu is the export. It will be a dwp or webpart file extension upload that into the web part gallery in site settings Jul 25, 2018 at 10:26
  • after uploading the webpart, I have tried to select the webpart in web part gallery, and it returns an error "Cannot create an object of type 'System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' from its string representation '(Collection)' for the 'Links' property."
    – Wee
    Sep 7, 2018 at 1:58
  • what you encountering is a seperate issue, please ask an additional question Sep 7, 2018 at 4:14
  • Hi James, I have post a new question at sharepoint.stackexchange.com/questions/248568/…. Hope you can assist. Thanks
    – Wee
    Sep 7, 2018 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.