Question

How can I set a web part so it will be automatically appended to a web part zone when a specific page layout is selected?

The solutions I have tried so far is:

  1. Using <ZoneTemplate> under <WebPartZone> and putting my webpart in there
  2. Adding .webpart-code directly into <AllUsersWebPart> where I define the page layout, in elements.xml
  3. Put the web part on the page layouts programmatic when creating site structure (deployment script)
  4. Add a hook that hooks in and adds the web part

Problems with the solutions:

  1. The web part seems to become static, and can not be removed after it's created.
  2. would have to put .webpart-code in both a .webpart-file as well as in elements.xml (I want it to be stand alone as well as set by default). And making a mess in my elements.xml.
  3. Web part will only be deployed first time, so when creating a new page with the page layout, the web part will not be included.
  4. We do not know how to do this, since page layout is set after creating the page. We do have hooks for setting default page layout based on where in the structure the page is created, here we can append the web part as well, but then the web part will only be added if you create a page on a specific location.
Was it helpful?

Solution

Since you are using SP2010 you should be able to use the WebProvisioned event to hook in extra functionality such as the one you ask.

In SP2007 I would use any of the above methods you mention depending on what i needed. The last one I would achieve by using a custom provisioning provider. Check out my other post on this here.

OTHER TIPS

I have been using your method 1. and 2. extensively. I cannot follow the problem you describe for solution 1. Apart from that have both solutions (1. and 2.) the drawback that all web parts are duplicated each time the feature deploying the pagelayouts is reactivated and you need some clean-up code to fix this.

I've been using number 1 way (on the original post) and it works perfectly. Web parts don't become static unless you have defined web part properties to disallow moving or closing web part, or if you don't have enough permissions.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top