Tuesday, July 24, 2007

Creating an empty page in MOSS 2007

A few days ago as part of a new project building a publishing web site in MOSS 2007, I struggled to create a page that renders as empty as possible. This means I didn’t want any of the sharepoint-ness to be seen on the page. One suggestion I got was to place an empty aspx in the _layouts directory, but this wasn’t satisfactory since I wasn’t looking for an empty page just for the sake of being empty, I was rather looking for a minimal set of features on a page still enabled with MOSS functionality. I could then add features as needed, but wouldn’t have to worry about residual MOSS junk on the page.

There are a number of resources on the web that helped me to ultimately achieve this, but I couldn’t find any step-by-step walkthrough so here is my attempt at such a thing.

Start with a master page. There are two ways to go creating a master page in MOSS. One is to create the master page from scratch and trying to ensure the minimal set of MOSS controls is on it. The other method is to hack up one of the master pages that you get with MOSS. Neither of these methods is simple or fun, so I did some digging to see if someone had been kind enough to do this work already and share. I found that MSDN has a minimal master page http://msdn2.microsoft.com/en-us/library/aa660698.aspx that seemed to be exactly what I was looking for. After some reading though it seemed that this master page didn’t work for everyone and there were hints that Heather Solomon’s was better. http://www.heathersolomon.com/blog/archive/2007/01/26/6153.aspx I ended up trying both and both seem to work. I ended up using Heather’s for no particular reason I can remember.

Once you pick a master page to use, how do you get it into MOSS? Fire up SharePoint Designer, point it at your site, and go to the _catalogs/masterpage folder. Use File>New>SharePoint Content>Page Tab>Master Page to create a new master page. Delete the contents and paste in the master page code of choice. Save it, and set it as the default master page for the site by right clicking on it and choosing Set as Custom Master Page. Do NOT pick Set as Default Master Page. The reason for this is that the custom master page is used for any pages you create in the site. The default master page is used for any SharePoint specific pages in your site, like the site settings page. Perhaps there is a good reason to mess with this but it’s not in the scope of this document.

You should now be able to open up a page in your site and see the effects of changing the master page. Most likely the effect will be that a bunch of the MOSS features are still on the page, but they are ugly since the styling has been ripped out. They are ‘bare’ so to speak. No fear, you are on the right path. The next step is to move all the MOSS controls to a hidden panel. Heather Solomon’s page includes a panel with visible=false set on it just for this purpose, so after some experimenting I realized you want to take everything out of the form tag except the web part manager and the asp content placeholder for main content, and move it to the hidden panel. Save the master page like this and see what a page looks like. It should have lost a LOT of the MOSS stuff.

Now it is time to create a new page layout that also doesn’t have any MOSS junk on it, so that combining this with the new master page will result in the empty page we are striving for. I struggled for quite some time with this part, only to find out that you need to publish page layouts before they work. If you do not publish a page layout, you get strange behavior when you try to look at the page as an anonymous user. If you are using IE7, somehow it remembers who you are (even when I pushed all the buttons to forget passwords and any other history) and it logs you in. Not cool, since a public user will not have a username / password cashed. Firefox pops up a login box. More acceptable but still uncool since we want the page to just show up. If you check the IIS logs, you’ll see that you are getting a 401.5 HTTP error. Bottom line – publish the thing.

For sake of completeness I will briefly list the steps you need to do in order to create a page layout, the resources that helped me get there was a blog posting by Scot Hillier http://ablog.apress.com/?p=1248.

Define any site columns and then the content type that you will need. This is done using the web interface of MOSS. Next use SharePoint designer to create a page layout in the _catalogs/masterpage folder of the root site of the site collection. Use File>New>SharePoint content>SharePoint Content Tab>Page Layout and if all is well you should be able to pick the content type you created in the dropdown in this dialog. At this point you can add whatever controls you want to the page layout, if you are going for a minimal (empty) page though, you should have a asp:content placeholder for the page title and another for the main content – and that’s it. If you now save the page layout, right click it and choose publish, you should be able to get the page layout published and approved.

You are now ready to create a new page using the standard MOSS web interface based on your new page layout and new master page. This page will render as an empty page, so do remember that you will not be able to run the WCM functionality from it and will therefore need to approve it using the ‘show all site content’ page in your site. If you do want the editing console, take it out of the hidden panel in the master page and move it back into the form.

No comments: