Andrew Connell

Having Default Web Parts in new Pages Based Off Page Layouts in MOSS 2007 Publishing Sites

One question I get quite often and see in various forums is “can you specify a default Web Part(s) to include in a Web Part Zone on a particular page layout in a Publishing site when a new page is created off that page layout?” The answer is yes… yes you can most certainly can.

If you are adding your page layouts to the Master Page Gallery by provisioning the files into the gallery using Features, you can very easily specify the default Web Part to include in a Web Part Zone. The first step is to make sure you have a Web Part Zone in the page layout… such as the following zone I’ve added to my page layout’s PlaceholderMain content placeholder:

Scaled image

Page Layout's 'PlaceholderMain'

Then, within the element manifest file where you are provisioning the page layout into the Master Page Gallery as an uncustomized file, use the node to specify the Web Part as follows:

Scaled image

Provisioning a web part

In the CAML shown in the previous image, the DivisionArticleImageLeft.aspx file is being provisioned as an uncustomized instance in the Master Page Gallery. After setting a handful of fields such as the PublishingAssociatedContentType, PublishingPreviewImage, ContentType and Title, the next thing to do is specify what will go in the Web Part Zone. This is done by using some XML to specify the assembly and full name of the Web Part class as well as any default values to set on the public properties. In the case above, the Image Web Part is added to the Main Web Part Zone and the image URL is set to the SharePoint green “spinner” animated image. Then, when new pages are created, they will automatically start out with this one Web Part as you can see below:

Scaled image

Default new pages

There… now I finally have something I can point people to!

Andrew Connell
Founder & Chief Course Artisan, Voitanos LLC. | Microsoft MVP
Written by Andrew Connell

Andrew Connell is a web developer with a focus on Microsoft Azure & Microsoft 365. He’s received Microsoft’s MVP award every year since 2005 and has helped thousands of developers through the various courses he’s authored & taught. Andrew’s the founder of Voitanos and is dedicated to delivering industry-leading on-demand video training to professional developers. He lives with his wife & two kids in Florida.