This is a repost of an article i upped on my blog back in Feb 2007
Purpose:
Apply a Sharepoint Theme to any provisioned webs based off
any Site Definition via Feature Stapling.
Background:
A pre-deployment task for our implementation of
WSS 3.0 is to brand Sharepoint. There are several ways to customize a
Sharepoint implementation. One of the simpler methods is to create your
own Sharepoint Theme.
Themes, once applied to a Sharepoint web, allow you to
skin the look and feel of a significant portion of the pages that
users come into contact with whilst using a site. We required
fairly minimal customizations which were mostly serviced through custom
stylesheets.
In our implementation of WSS 2.0 we used a custom site
definition (based off the STS site def) to service our branding needs,
along with modifications to bunch of admin pages on the front-end servers.
We could of taken the same approach of creating a new
custom site definition which would give us more flexibility in terms of
customization, but this approach isn't favourable due to the fact
that we wanted all of the OOTB site definitions available for use, not just the
standard team site definition.
Yes, we could create a custom site def based off each of the
default site defs (STS, MPS, WIKI, BLOG etc), but this approach is no longer
necessary for simple customizations due to a new feature in
Sharepoint called umm.. Features. A
Feature as defined in the SDK manual:
"Features reduce the complexity involved in making
simple site customizations, and are robust when upgrades are applied to a
deployment. Features eliminate the need to copy large chunks of code to change
simple functionality. Features thus reduce versioning and inconsistency issues
that may arise among front-end Web servers. Features make it easier to activate
or deactivate functionality in the course of a deployment, and administrators can
easily transform the template or definition of a site by simply toggling a
particular Feature on or off in the user interface"
Another alternative would be to directly modify the OOTB
site definitions. This however is not supported. So what we wanted in a nutshell is a way to skin any type of
Sharepoint site with as few modifications to Sharepoint files as possible.
The solution also had to have three main
features:
Req 1. Our custom Theme needs to be applied to sites
automatically. (The standard process to apply a Theme is a
manual one, 'Site Actions->Site Settings->Look and Feel->Site
Theme')
Req 2. Any changes made to the custom Theme post deployment, must be
reflected in existing sites that were provisioned after this solution was
deployed.
Req 3. Modify as few Sharepoint files as possible
Solution:
A quick rundown of the solution is as follows:
1. Create a custom Theme. CSS importing is used to get
around Sharepoint caching a copy of the Theme's css file, which would violate
Req 2.
2. Create a Sharepoint Feature that applies a Theme to
a site when a site is provisioned.
3. Create another Feature that staples the previous Feature
to all site definitions. This idea came from Chris
Johnson's blog.
4. Deploy the second feature at the Farm scope,
which attaches the first feature to all sites within the Sharepoint farm. For
ease of deployment i have used the WSS Solution framework.
Detailed Description:
1. Creating a Theme is detailed here WSS 3.0 SDK - How
to: Customize Themes or alternatively read Shane Perran's blog. In order
to utilize the css 'indirection' method see Bil
Simser's "Automagically updating themes" blog entry
2.
Feature.xml


ApplyTheme.cs

3.
Feature.xml

Elements.xml

4.
I have attached the VS 2005 solution. All you need to
do is replace the GUIDS and Public Keys, sign the assembly and fix up any
broken references. Oh and change names of classes, dll, etc so they mean
something to you.
See the Sharepoint
Solutions Team blog for an example VS 2005 solution, explaining
all the files in the project and also check out Andrew Connell's HowTo
on creating Solution files.
To deploy the Solution, here is a script that was posted by
Daniel Larson on the SDK page Deploying a
Solution.
@set PATH=C:\Program
Files\Common Files\Microsoft Shared\web server extensions\12\BIN;%PATH%
stsadm -o deactivatefeature -name MyCustomTheme -url http://localhost
stsadm -o retractsolution -name MyCustomTheme.wsp -immediate -allcontenturls
stsadm -o execadmsvcjobs
stsadm -o deletesolution -name MyCustomTheme.wsp -override
stsadm -o execadmsvcjobs
stsadm -o addsolution -filename C:\MyCustomTheme.wsp
stsadm -o execadmsvcjobs
stsadm -o deploysolution -name MyCustomTheme.wsp -immediate -allcontenturls
-allowGacDeployment -allowCasPolicies
stsadm -o execadmsvcjobs
Limitations:
The solution does not automatically apply the Theme to any
sites that have already been provisioned.
Any feedback is appreciated,
Tom.
(Originally) Published Monday, February 19, 2007 11:42 AM by
Tom.Shirley