- Have users manually set a theme after creating a site (ugly!)
- Set the company theme to a site, and save it as template and deploy the template globaly in the server (complicated, and also disconnects the sites from the file system templates, making it hard to change in the future)
- Change the default css files and not use the theme (extremely ugly - why are the themes for??? also does not support multiple templates with different themes)
The solution I found for the problem (thanks to Kalmberg) is to add in the site definition a link to a custom page that will run code when the site is created. the code will apply the theme to the new site.
Kalmberg example was instructive, but allow me to take you through the proccess step by step:
Step 1 - Changing The Site Definition
- Create the site definition that you want
- Go into the "xml" folder and open the "onet.xml" file in notepad or visual studio (or any editor)
- Find the "Configurations" tag at the bottom, and for every configuration you want to change add the following in the "Configuration" tag (where it says "THEMENAMEHERE" write your theme name. This may be case sensative): <ExecuteUrl Url="_layouts/1033/ThemeSetter.aspx?Theme=THEMENAMEHERE" />
Step 2 - Creating the ThemeSetter ASPX Page
- Open "C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033"
- Create a new text file, rename it to "ThemeSetter.aspx"
- Open the file for editing, and paste the following code into it:
<html dir="ltr"> <%@ Page Language="C#" ValidateRequest="False" %> <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=184.108.40.206, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=220.127.116.11, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <% SPWeb myNewWeb = SPControl.GetContextWeb(Context); myNewWeb.AllowUnsafeUpdates = true; myNewWeb.ApplyTheme(this.Page.Request["Theme"].ToString()); myNewWeb.Update(); Response.Redirect(myNewWeb.Url); %> </html>
Step 3 - Reset the IIS
for the changes to take affect, you will need to reset the IIS.
Now, create a site from the site definition, and the site should automatically be with the theme.