Friday, June 5, 2009

updating a layout using features

It is well known now that probably the best way to use site definitions and features is to start off with the most basic definition and do as much as possible in the feature. That also includes things like page layouts and master pages.
Words of warning. Ghosting and Unghosting can trick you into thinking that the updates are not working. As soon as you decide to customise a page using SPD which was deployed via a feature, SharePoint will put a copy into the database and always load that one instead of the ghosted one on the file system. Thus you can update your feature as often as you like, you won't see the changes. Solution?
make sure you have all modificaitons in the source file and reset the layout page to Site definition. Strictly speaking it never was part of a "site definition" but part of a feature, so you won't find the Reset button in SPD, but you can still reset it manually using the web interface. Simply copy the url of the page in question, go to Site Settings and there you will find a link to Reset to Site Definition where you can past the link.

Something Else I noticed though. If you customise the layout page to include web parts on creation using the AllUsersWebPart tag, like the Table of Contents Webpart in Andrew Connel's Minimal Site Definition example, each time you reinstall the feature a new instance of the web part will be added to the layout definition, causing multiple instances to be created on the new page creation. So try to stay away from web part customisation in layouts if you can.

Finally, you might want to make other property changes, like providing a new Preview image url or modifying the content type or such. These settings live on the list item and not in the file. Editing the item will solve those problems but as soon as you check your changes in, the page will be unghosted and you're back at the first dilemma. No worries though. Simply reset to site definition again and you're as good as gold. Yup, the changes to the list item don't go lost when doing that reset, so you won't lose those updates.

Regards

No comments: