More in this section
Blogs RSS feed

Create a Sitefinity Theme in a Class Library

by Atanas Valchev

This blog post will outline how to create a Sitefinity Theme in a class library.

To start, if you do not have a Theme, you can generated one with Sitefinity Thunder. After that, add a new class library and move the theme files to it:

In order to be able to resolve the assembly when registering the theme, we need to add an empty Reference.cs class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CustomTheme
    public class Reference


After that, the theme can be registered just like a regular theme: The full namespace path is: CustomTheme.WebsiteTemplates.WebsiteTemplates1.App_Themes.WebsiteTemplate1. You will notice that for the assembly we enter the Reference class, otherwise we will not be able to resolve the assembly. Since we are using a separate assembly, the build action for all resources need to be changed to Embedded Resource.

The next step, is for all the stylesheets, JavaScript, etc. to be added as WebResources in the AssemblyInfor of the Class Library that we put the Theme in:

After the solution is built, the theme, master pages and resources will be in this assembly. In order to use the master page, you will need to apply using the API. First, register a Virtual Path:

After that, create a new one or get an existing template and apply it like this:

var pageTemplateId = Guid.Parse("a7ff55b2-41b2-63fe-9626-ff0000474a57");
          PageManager pageManager = PageManager.GetManager();
          PageTemplate template = pageManager.GetTemplate(pageTemplateId);
          var master = pageManager.TemplatesLifecycle.GetMaster(template);
          master.MasterPage = "~/CustomTheme/THE_PATH_TO_THE_MASTERPAGE";


 More information on the page templates API can be found here:Page Templates


Leave a comment