Create a Sitefinity Theme in a Class Library

Create a Sitefinity Theme in a Class Library

Posted on January 17, 2014 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

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: http://screencast.com/t/m6mlNPlOkMs.

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: http://screencast.com/t/9QxVLnI5pfx. 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: http://screencast.com/t/2hMVo27Dp

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: http://screencast.com/t/93OT4fokT42n

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";
 
          pageManager.TemplatesLifecycle.Publish(master);
 
          pageManager.SaveChanges();

 

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

 

Atanas Valchev

Atanas Valchev is a Tech Support Engineer at Telerik. He joined the Sitefinity Support team in March 2012.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation