This post tries to combine some best practices for designing your own non-publishing team site template. Of course, this is how I think it works out best, but don't accept it as the truth. Any discussions are welcome. I will discuss the site definition, onet.xml, master page, page layout, _layouts application pages, custom theme, and custom feature for applying the theme automatically. I will also try to make this post as compact as possible (not very likely). So if you have questions, just ask!
Many examples on the Internet show you how to customize SharePoint 2007. Most of these articles are using browser customizations (through settings) or customizations using SharePoint Designer. Most of these articles are not very concerned about how to deploy. Often, it leads to templates which have to be applied to every site and sub site. Pages tend to be ghosted which means that whenever the look and feel changes afterwards, you'll have to apply it to all sites and sub sites. Not very handy.
My approach describes how to create a deployable solution which fits perfectly in a developer-centric WCM approach. I do not prefer the author-centric approach. In a developer centric approach the master page, page layout and custom web parts and server controls are tied together closely. Designs are released like new web parts using solutions and features from development to QA to staging to Live. On the Microsoft site there has appeared a nice WCM architectural discussion which describes this far better than I do.
Very important! Pages should be unghosted meaning that we can change look and feel afterwards very easily and changes are reflected on all sites immediately.
Pain in the .... We all know that you can redesign your master page, page layout and CSS but even then the application pages are unaffected. Why? Because they are shared across all sites. Application pages are pages from the _layouts directory and are using a different master page called application.master. It is not best practice to change the application.master. I have seen people creating copies of the directory and change the path of the virtual directory through IIS for each web application. Or even writing custom HTTP handlers to apply a different master page runtime.
Our solution applies a theme to the whole site, including application pages. Of course, that will not change the layout of the application pages, but do you really want that to change? Think about support from Microsoft, Service Pack updates and so on.
Step 1. Create a site definition
Log in to one of your front end web servers. Browse to the famous template directory. There is a folder called sitetemplates. This folder contains many site definitions for team sites, meeting workspaces and publishing sites. This post will not describe how to redesign a publishing template. Many examples on the Internet already do. Just keep in mind that this post is about a non-publishing, basic team site.
The basic team site is located in the STS folder. We will create a new design and take this one as a starting point.
1. Create a copy of the existing sts site definition, in my case called SPDomestic
Step 2. Add master page to site definition
Inside your new SPDomestic folder you will find a default page layout called default.aspx and a file called ONET.XML. There is no master page in this folder yet. We will take a copy of the default master page which is located in the GLOBAL folder and called default.master.
2. Next, create a copy of default.master and put it in the site definition folder SPDomestic. Rename the file (in our case called domestic.master)
3. Edit ONET.XML in your new site definition folder
4. For each configuration tag, add the following attributes: CustomMasterUrl="_catalogs/masterpage/domestic.master" MasterUrl="_catalogs/masterpage/domestic.master"
5. Add a module where you provision the domestic.master file to the _catalogs/master folder.
First you'll have to define your module (look at one example that is already there), next you'll have to add the module to your configuration.
6. Open default.aspx from your site definition with notepad and change the masterURL property of the first line to: MasterPageFile="~masterurl/custom.master". Note: not domestic.master but just custom.master. That is a predefined token which will resolve to domestic.master.
This step often goes wrong. People tend to use the exact name of their new master page. Wrong. SharePoint only allows several tokens there. They are all listed in the SDK.
Step 3. Add imagery
7. Put your custom imagery where you want, but I found it very convenient to put them in _layouts/1033/styles/spdomestic.
Why? Because images from the stylesheet, master and page layout all use different relative paths and you cannot always use $SPURL:~sitecollection in all controls or HTML tags. Now you can use /_layouts/1033/styles/spdomestic/ as a reference everywhere!
Step 4. Add the template to the farm
Finally, create a new webtempXXX.xml file and specify your new template SPDomestic. Perhaps you'll need to IISReset your front end.
At this point you'll see a new site template on the site creation page. Try to create a new site using the new SPDomestic template. If that goes OK: congratulations. If not, check your ONET.XML, Default.aspx and webtempxxx.xml if you made any typos.
Step 6. Change master page and page layout
If it works, then I would suggest to make changes to your new master page and default.aspx located in the new SPDomestic folder. Changes are immediately visible on the site because the site is unghosted.
Step 5. Create and auto apply custom theme
You'll probably want to override some CORE.CSS style sheet definitions.Install IE Developer Toolbar to make your life a lot easier (select: Find element on click).
Overriding the default CORE.CSS will only work well when you apply a theme. The theme CSS will be included after the CORE.CSS. If you would for instance add a CSSRegistration control in the master page, the style sheet would be included BEFORE the CORE.CSS. Making your life very miserable.
Another reason to create a theme are the _layouts pages. We want to style them a little bit as well.
Now, create a new theme. In our case it was called SPDomestic. Override any CSS definitions from the CORE.CSS.
Tip: the definitions in the CORE.CSS are numerous. Often, the sequence of all definitions determine the final look and feel. If you would for instance override the ms-navitem definition, you should carefully copy ALL CSS definitions where ms-navitem is part of and use them in exactly the same sequence. If you would start copying single definitions, then you might encounter problems when you start mixing the order in which definitions are applied. Even better? Copy the whole CORE.CSS (yes, I know it is a lot) to your theme.css and make changes to the theme.css.
Make sure that the theme will be applied automatically. I’ve used the themechanger feature from CodePlex by adding the feature to the ONET.XML (instead of stapling). Not the themechangerstapler. Just the themechanger feature (packaged as a solution). You can add the feature to the ONET.XML of your site definition, configure the XML of the ThemeChanger feature to select your new theme, and there you go: every site or sub site will have the theme applied automatically. That is: only for your new site definition.
Step 6. Package, deploy and store
Package the site definition, imagery and webtemp files as a solution and you’re done!On CodePlex there is a great tool for that. First create a Visual Studio solution. Next, use the tool to autogenerate a /12/ folder, a /bin/ folder, a /gac/ folder and a /80/ folder. Put your site definition inside the 12/template/sitetemplates folder, your imagery inside the /12/template/layouts/styles/ folder, your theme inside the /12/template/themes folder. All at exactly the same locations as on the front end server. Now, run the tool and it create a solution file automatically. Make sure you'll have a copy of all the new files before deploying the solution. Use stsadm -addsolution ... to add it to the FARM. Use ststadm -o deploysolution -immediate ...... to deploy it to a web application or globally. After a few minutes your new design will be deployed to all front end servers in the farm. Upload your solution file to your configuration management system like Visual Source Safe and you're done.
Any tips, suggestions are welcome!