Office 365 – SharePoint Online – Classic mode – Adding webpart in custom page layout. Webpart will by default added when new page will created using our page layout

Hi All,

We faced one very wired issue and finally solved it. So thought to share πŸ™‚ It took lots of mine time and research.

Use Case: In SharePoint online classic mode when we need to create new page using our custom page layout, we need OOBweb part (In our case Contacts webpart, here any web part will work) should be available by default on the page.

Background: We have migrated our SharePoint 2013 on-premises site to SharePoint online in classic mode. In SharePoint 2013 we were using feature to associate the web parts to our custom page layouts. So when new pages are created using our custom page layouts those web parts were appearing on the page.

But then this become challenge after migration to SharePoint online in classic mode. We don’t have feature option in SharePoint online. So we have option of editing the page layout adding web part in it and trying. This took the time for me and bit research. Googled bit but no luck soon.

Solution: After bit googled and lots of trial error with page layout, finally found the way.

Here we will take example of Contacts web part since we need to add Contacts web part on our news pages.

We have ContactFieldControl available in Microsoft.SharePoint.Portal assembly and namespace is Microsoft.SharePoint.Portal.WebControls

so we need to add register tag for this assembly in page layout as

Now we need to add WebPartZone in page layout. WebPartZone is available in Microsoft.SharePoint assembly and namespace in Microsoft.SharePoint.WebPartPages

so we need to add register tag for this assembly in page layout as

Then we will add web part zone in page layouts as

Finally, we need to add ContactsField webpart in above webpart zone as

Uploaded our page layout in masterpages gallery and tried by creating new page. It worked like charm πŸ™‚ Existing pages also updated. On all existing pages as well ContactField webpart get added.

Thanks for reading πŸ™‚

Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.

Stay tuned on Knowledge-Junction, will come up with more such articles.

Advertisements

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.