Microsoft MVP Logo

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:

WebPartZone

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

WebPartZone2Click image for a larger resolution

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:

WebPartZone3

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

Comments powered by Disqus