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:
<WebPartZone>and putting my webpart in there
- Adding .webpart-code directly into
<AllUsersWebPart>where I define the page layout, in elements.xml
- Put the web part on the page layouts programmatic when creating site structure (deployment script)
- Add a hook that hooks in and adds the web part
Problems with the solutions:
- The web part seems to become static, and can not be removed after it's created.
- 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.
- 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.
- 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.