How to add master page with styles and images in site definition
May 16, 2009

There is often a requirement to add customized master page (with images and css) while creating a site definition. Here I’m going to explain “How to add these items while creating a site definition”. As you can see in the following image, under “12->SiteTemplates->NACBAChapterSite” folder there is one master page “Chapter.master” that will be used while creating a site using this template. Supporting images and css files are placed under “styles” and “images” folders.Now, our goal is to put these files in master page gallery when the site is created using this template. To achieve this, do the following in “onet.xml” file (see above solution structure image). Below image shows the structure of my Visual Studio solution structure
  • Add the following entry under “node

<listtemplate Name="mplib" DisplayName="$Resources:MasterPageGallery;" Description="$Resources:global_onet_mplib_desc;" SetupPath="globallistsmplib" Type="116" BaseType="1" Path="GLOBAL" Hidden="TRUE" HiddenList="TRUE" NoCrawl="TRUE" Unique="TRUE" Catalog="TRUE" OnQuickLaunch="FALSE" SecurityBits="11" AllowDeletion="FALSE" AllowEveryoneViewItems="TRUE" Image="/_layouts/images/itdl.gif" AlwaysIncludeContent="TRUE" DocumentTemplate="100" />

  • Add following entry in thenode
<module Name="MasterPage" />
<module Name="Images" />
<module Name="Css" />
Here first module entry is to locate master page, second one is to locate different images and the third one is used to add CSS files.
  • This step actually adds the files to the master page gallery. Add the following entry under “” to add chapter.master to the master page gallery
<module Name="MasterPage" List="116" Url="_catalogs/masterpage" RootWebOnly="FALSE">

<file Url="Chapter.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

</module> Here "Name=MasterPage" refers to the module entry created in step 2. Similarly to add css add the following entry under "<project><modules>"

<module Name="Css" List="116" Url="_catalogs/masterpage/styles" Path="styles" RootWebOnly="FALSE">

<file Url="color_layout1_blue.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

<file Url="color_layout1_green.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

<file Url="color_layout1_orange.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

<file Url="color_layout1_purple.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

<file Url="color_layout1_red.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

<file Url="template_layout1.css" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

Same you need to do for the images.
Once done with the above steps, you need to deploy the solution. You can do this with WSPBuilder or MSBuild. Deployment is not in the scope of this article.

Leave a Reply

Your email address will not be published. Required fields are marked *


Related Posts

SharePoint chart using excel services

Sometimes there is a need to display chart embedded in excel sheet. SharePoint…

Feb 10, 2012

FileNotFoundException sharepoint 2010

You may see error like Unhandled Exception: System.IO.FileNotFoundException: The Web application at http://sp2010:12523…

Nov 5, 2012

Retrieving text from RichTextField control of SharePoint

If you are new to using SharePoint’s RichTextField control, then you are most…

May 30, 2012

Copyright © Prakash Software Solutions Pvt. Ltd. All Rights Reserved.