Friday, January 21, 2011

Using Sharepoint 2010 Theming Engine



Now a days I am working at Sharepoint 2010 project. Currently doing some theming stuff in my webpart .

I read alot about theming in Sharepoint but didn't get too much or faced some problems when I followed some blog. Them I decided to share this with you.



Sharepoint 2010 is introduced with a very intelligent theming. It uses THMX file for actual theming. you can create theme in powerpoint and save it as THMX then use in Sharepoint theme. but we are not creating new theme we are going to use existing theme to create out own classes so that we cant use those classes in our webparts.So Here we’ll just use the theme and create our css class file that will use current theme colors. To do so, we need to follow two steps



Step 1:- Need to place the css at right place.

From Sharepoint Designer:

If you use sharepoint designer to create themable file then just open site in sharepoint designer and got to “All Files/Style library/Themable”

if Themable is not exist then just create a folder give any name to it and create a CSS file in it.

Write all the theme css in it save the file. our first step is done now.



From Visual studio 2010:

If you use visual studio to create the themable file then in sharepoint project add a sharepoint folder “/_layouts/1033/STYLES/Themable”. Now creat a CSS file “xyz.css” in the themable folder and write your class in it and deploy the code.



Step 2 :- Need to register the css file properly.

From Sharepoint Designer:

Just open master page which is being currently used in sharepoint site and edit this master page and add the below line of code in head section. Save the master. Now when you run the site you theme class will render every time.













From Visual Studio 2010:

Open any webpart in which you want to use your custom theme classes. then add below line of code . Now deploy the code.






Our work is done, we created and  registered the files properly. Now change the theme of site once and now you are ready to your custom theme classes in your webpart.



Working of Sharepoint Theming Engine:

Sharepoint provide 12 set of colors and 2 font  and use some permutation and generate 5 different sheds(lightest, lighter, medium, darker, darkest) of color from these 12 colors



dark1, dark2, light1, light2, accent1, accent2, accent3, accent4, accent5, accent6, highperlink, followedhighperlink



sharepoint use 3 methods to replace your default color with theme color

ReplaceColor, ReplaceImage, ReplaceFont



The theme engine read the commented code in css file and repalce the default color with theme color. In my example comment line has ReplaceColor. this theme engine method pick dart2-Lightest color from the theme and replace #000000 color with actual theme color.



/* [ReplaceColor(themeColor:"dark2-Lightest")] */ background-color:#000000;





The same treatment is used for image also but the method is ReplaceImage.

/* [RecolorImage(themeColor:"light1-Lightest",method:"Tinting")] */ background:url("/_layout/images/spdicon1.png") no-repeat;

The image coloring user three method tinting, blending, filling.



I am shocked to see the coloring of image. its very real. no one can believe that the image is colored by engine. it is very nice.



We can also use the font family which is used in theme using ReplaceFont method of theme engine.
.majorfont {
/* [ReplaceFont(themeFont: "MajorFont")] */ font-family:Arial;
}
.minorfont {
/* [ReplaceFont(themeFont: "MinorFont")] */ font-family:Arial;
}